ali_2kool2002 Posted April 21, 2007 Share Posted April 21, 2007 Hi can someone explain how the code works so at least i know how php does it instead of just using it from here the first code checks if there are no numbers in the text field for name but what do those characters in preg match mean same applies for how does the email validation work? Thanks for anyone to crack this cheers : if ( !preg_match('/^[a-zA-Z\" "]*$/', $yname) ) { error('Name is not Valid.\\n'. 'Please try again.'); }Repeat it for every text box u want to validate. Use this for email validation: Code: if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $yemail)){ error("Invalid e-mail address"); } Quote Link to comment Share on other sites More sharing options...
keeB Posted April 21, 2007 Share Posted April 21, 2007 Those are called Regular Expressions (regex for short.) They're a pain in the butt to learn! Quote Link to comment Share on other sites More sharing options...
taith Posted April 21, 2007 Share Posted April 21, 2007 [_a-z0-9-] --> any letters, a-z, or numbers 0-9 (\.[_a-z0-9-]+) --> followed by a maybe a "." , and any letters/numbers @[a-z0-9-] --> an @ symbol, followed by any letters/numbers (\.[a-z0-9-]+) --> followed by maybe a ".", and any letters/numbers (\.[a-z]{2,4}) --> followed by a dot, and any letters/numbers, thats between 2-4 characters long if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $yemail)){ error("Invalid e-mail address"); } if that helps any... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.