Validating e-mail and website addresses using regular expressions
While filling out web forms it is common to ask a user for an e-mail ID and a website name. These values are a little bit different from the normal strings as they have a fixed pattern. E-mail addresses require @ symbol whereas website addresses generally start with http or https. These and many other conditions are required by such addresses.
This is where regular expressions come to the rescue. This recipe will show you the use of regular expressions to validate patterns like e-mail addresses and URLs.
Getting ready
Create a new folder named Recipe5
inside the Chapter5
directory.
How to do it...
Create a file named
index.html
inside theRecipe5
folder. Similar to the previous recipe, create two textboxes—one for entering the e-mail address and another for the website address. Also, assign a CSS classmail
to the first textbox andsite
to the second one.<html> <head> <title>Search</title> <...