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. Link to comment https://forums.phpfreaks.com/topic/83025-solved-validating-characters-in-urls-e-mails-and-ages/ 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 Link to comment https://forums.phpfreaks.com/topic/83025-solved-validating-characters-in-urls-e-mails-and-ages/#findComment-422302 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. Link to comment https://forums.phpfreaks.com/topic/83025-solved-validating-characters-in-urls-e-mails-and-ages/#findComment-422315 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'; } ?> Link to comment https://forums.phpfreaks.com/topic/83025-solved-validating-characters-in-urls-e-mails-and-ages/#findComment-422317 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. Link to comment https://forums.phpfreaks.com/topic/83025-solved-validating-characters-in-urls-e-mails-and-ages/#findComment-422331 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.