So far, you've seen some of the commands that you can use to validate forms using jQuery, and how you can limit your checks to specific field types (such as e-mail addresses) or override the error message displayed on the screen.
The code will fail though, without some form of validation template that we can use to check—the keen-eyed amongst you may have noticed this, in our basicvalidation.html
demo:
pattern = "[^ @]*@[^ @]*\.[a-zA-Z]{2,}";
The pattern
variable is used to define a regular expression or a regex statement. Put simply, these are single-line statements that dictate how we should validate any entries in our form. These are not unique to query though; they can be equally used with any scripting language, such as PHP or plain JavaScript. Let's take a moment to look at a few examples in order to see how this one works:
[^ @]*
: This statement matches any number of characters that are not an@
sign or a space@
: This is a literal\.
: This is...