Page 1 of 1

form validations

Posted: Fri Jul 16, 2010 12:52 pm
by heshan
Hi,

I want to know how to check whether email entered by users is in valid format in my registration form.
And i also want to know how to allow strings only in typing name, address etc.
And also numbers only in national id field.

ThankYou,
Heshan.

Re: form validations

Posted: Fri Jul 16, 2010 5:48 pm
by JakeJ
There's plenty of information out there on what are called "regular expressions."

The primary tools in php for executing regular expressions are preg_match() which just performs a test to see if conditions are or are not met and preg_replace() that will will modify the text that meets certain conditions.

There are also regular expression builders out there to help you.

Gotta warn you though, they can be complicated. Regular expressions for email addresses are plentiful but it's a subject you should explore in any case.

Personally, "regex" as it's also known confuses the crap out of me and I feel like I'm starting from scratch ever time I have to make one.

Re: form validations

Posted: Sat Jul 17, 2010 6:03 am
by DaiLaughing
I agree with Jake. The answer is regular expressions but the answer may be worse than the problem. Most of the examples I have seen out there will fail in some way or another. As someone from the UK it's glaringly obvious that a lot of the expressions don't allow for two-letter country codes such as co.uk.