Folks,
Need people to submit me their valid URLs on my form. How to make sure URL is valid ?
Which PHP function to use without using regex ?
Look how messy regex is:
[code]
$website = test_input($_POST[“website”]);
if (!preg_match(“/b(?:(?:https?|ftp)://|www.)[-a-z0-9+&@#/%?=~_|!:,.;]*[-a-z0-9+&@#/%=~_|]/i”,$website)) {
$websiteErr = “Invalid URL”;
}
I don’t like copy and pasting code from tutorials to my website. And so usually, I memorise the PHP function from tutorial then experiment by coding the function in many ways and then stick to what works for me best. That way, I never copy and paste code from others.
Now need to make sure people submitting valid URL. Impossible to memorise all that regex. And like So said, I ain’t copy and pasting either the code you see above from w3schools.com.
And so which PHP function, without regex, will do the job ? Is not FILTER_VALIDATE_URL enough to validate all form of URLs ? That regex you see above is not really needed. Right ?
Likewise, is not FILTER_VALIDATE_EMAIL not enough in PHP ? I don’t need another regex here do I ?
Also should not html 5 “<input type=URL/email ” be enough ?