/    Sign up×
Community /Pin to ProfileBookmark

HowTo Validate URL & Email Without Regex ?

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”;
}
[/code]

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 ?

to post a comment
PHP

1 Comments(s)

×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...