[eluser]Colin Williams[/eluser]
Quote:Is a Regex the only way to go?
Don't fear the regex. It might be better than getting uber-creative with standard PHP functions. If you're worried about resources, just do it and run benchmarks on it. THEN decide if it's too heavy. I've never had so many preg_ functions in my code that it crippled a site (3 million page views, 800k+ uniques, in one day, if you're wondering how big).
Code:
if (strpos('http://', $str) !== 0 and strpos('https://', $str) !== 0 and strpos('@', $str) !== FALSE)
{
// It must be an email
}
else
{
// It looks like a url
}
Is that ironclad? No. Do you need to protect against every single edge-case? Probably not.
Quote:The validation for the Post a Job page is 5 conditionals deep already
Is that the most evil thing ever? Not if it's the only logical way to run the checks. I like to get things working first, then come back and refactor. No sense it letting perfect destroy good. Just comment the code with a todo:
Code:
// TODO: Consider refactoring this mess!