DavidGS Posted December 24, 2007 Share Posted December 24, 2007 OK, so I need a code to validate that a user's e-mail address, URL and age entered into a form is valid (syntax). I have the form set up and it works and writes information to a database. It checks that a URL entered isn't already in a database and same with the e-mail. All I want it to do now is check that that the e-mail address entered is in the correct format, to check if the URL entered only contains letters, numbers and underscores and the age entered is actually a number. For the e-mail validation, it should accept e-mail addresses from top-level domains other than .com (like .co.uk and .com.au), the URL validation should accept letters numbers and underscores and the age validation should only accept two-digit numbers (any zeros at the start eliminated). Any help would be appreciated. Quote Link to comment Share on other sites More sharing options...
asmith Posted December 24, 2007 Share Posted December 24, 2007 what you need : http://www.phpfreaks.com/forums/index.php/topic,96280.0.html BTW all "validating" things, sentences goes to this forum : http://www.phpfreaks.com/forums/index.php/board,43.0.html Quote Link to comment Share on other sites More sharing options...
DavidGS Posted December 24, 2007 Author Share Posted December 24, 2007 Hm, when I use this code to check if e-mails entered are valid, It always returns the same value, even if the e-mail isn't valid. if (!eregi("\b[A-Z0-9_%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b",$emailused)) {$validemail = 1;} else {$validemail = 0;} I just can't figure out why. Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted December 24, 2007 Share Posted December 24, 2007 See this, <?php if (preg_match('/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i', $emailused)) { echo 'Email entered is valid'; } else { echo 'Email entered is not valid'; } ?> Quote Link to comment Share on other sites More sharing options...
DavidGS Posted December 24, 2007 Author Share Posted December 24, 2007 n~ link=topic=174027.msg770040#msg770040 date=1198494359] See this, <?php if (preg_match('/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i', $emailused)) { echo 'Email entered is valid'; } else { echo 'Email entered is not valid'; } ?> THANKS! It works great. What would I enter if I didn't want any symbols other than a particular symbol in a string. Because I am making a website that lets you register your own personal URL (like MySpace) and I don't want to let the user enter any characters other than letters, numbers and underscores to prevent any errors with their URL. 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.