Form-Field Checking

As you can see, it isn't too hard to make a form a little more user-friendly. You can make the task of entering information easier on the user, but to make it worthwhile for yourself, you should check to see that the user has entered data that is actually useful. Otherwise, why collect it? Just checking to make sure that they filled in a field is not always adequate.

That's where ereg() comes in. ereg() is a built-in PHP function. It means Evaluate a Regular Expression. There is also a PERL-compatible function that works the same as ereg() (and may be a little faster) called preg_match(). The syntax for both functions is very similar, if not exactly the same in most instances. The syntax is:

ereg(search, string) 

where

Get Advanced PHP for Web Professionals now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.