form validations

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
heshan
Forum Commoner
Posts: 26
Joined: Tue Jul 13, 2010 1:16 pm

form validations

Post 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.
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: form validations

Post 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.
DaiLaughing
Forum Commoner
Posts: 76
Joined: Thu Jul 16, 2009 8:03 am

Re: form validations

Post 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.
Post Reply