Posts filed under 'jscript'
Regular expression & jscript problem
Few days ago when i was trying to validate a PHP page with javascript, i found something interesting. i like to share with u.
i was trying to validate a email id. for that, i write my own regular expression. i tried lots of combination’s of regular expression. but still it was not working. i wasted to much time on it !! lots of work to do. got worried !! why it was not working, though all the expressions were perfectly ok !! why!!
following are those expression:
var email_regExp="^[A-Z0-9._]+@[A-Z0-9.-]+.[A-Z]{2,6}$";var exEmailAdres="^([ tnrfv]*)([a-z]{1})[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+[.]([a-z]{2,4})([ tnrfv]*)$";var exEmailAdres="/w+([-+.']w+)*@w+([-.]w+)*.w+([-.]w+)*$/";var email_regExp="^[a-zA-Z][w.-]*[a-zA-Z0-9]+@[a-zA-Z0-9][w.-]*[a-zA-Z0-9].[a-zA-Z][a-zA-Z.]*[a-zA-Z]$";
now i solve it. can anyone tell me what was my fault ?!?
well the answer is i used double quote( ” ) instate of single quote( ‘ ). thats why it was not working.
var email_regExp='^[a-zA-Z][w.-]*[a-zA-Z0-9]+@[a-zA-Z0-9][w.-]*[a-zA-Z0-9].[a-zA-Z][a-zA-Z.]*[a-zA-Z]$';
REASON: When, i use double quote( ” ), the php parser can’t figure out the ‘@’ sign. and it try to do some action for this “@”. thats why the whole expression is not working. So, when its about to get a string value,its better to use single quote( ‘ ) instate of double quote( ” ).
6 comments August 14, 2008