Posts Tagged validation

Field validation with php

For creating a php file, at first we have to check all the fields input are valid. so, Field validation is our 1st step:

if(submit is ok){

if ( ! preg_match( “/^( [ tnrfv]* )+ ( [ a-zA-z_ ] ){ 4 , 20 }+/” , $fastname ) ){

$validation_flag=0;
$error_counter++;
}
else{
$validation_flag=1;
}

if ( ! preg_match( “/^( [ tnrfv]*)+( [ a-zA-Z0-9_- ]){ 4,20 }/”, $password ) ){
$validation_flag=0;
}else
$validation_flag=1;
if (!preg_match( “/^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)*.([a-zA-Z]{2,6})$/”, $email_address ) )   {
$validation_flag=0;
$error_counter++;
}else{
$validation_flag=1;
}

}

Add comment December 14, 2008

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


My Profile


# Software Eng. # Worked with C,C++, JAVA and PHP. #Love to play with codes. # Mostly like to do programming with 'C'. # I am not a CODER, but a DEVELOPER.

Admin Panel..

Life Cycle

December 2009
S S M T W T F
« Sep    
 1234
567891011
12131415161718
19202122232425
262728293031  

Clouds

cakephp codeIgniter desktop htaccess jscript linux mixed my words php regular expression

Just Posted

TOP R@TED

TaGs

cakephp codeIgniter desktop GP htaccess image upload installation jscript linux news password Personal Life php regular_Xpression script session validation

Archives

Top Posts

CoMmEnTs

Blog Stats

My Web Links

Web Links

RSS Xperts.PHP