Validating a form before it is submitted to the server saves bandwidth and time as errors can be trapped at the client side itself. A server request can thus be avoided. In a jQuery Mobile application, forms can be validated using JavaScript. This recipe shows you how to validate the entries made in a Blog Comments Form .
Copy the full code of this recipe from the code/05/validate-form
sources folder. This code can be launched using the URL http://localhost:8080/05/validate-form/main.html
.
In
main.html
, add the following code to create a form:<form id='commentform' action='#' method='post'> <div data-role='fieldcontain'> <label for='username'>Name</label> <input id='username' name='username' type='text' required placeholder='Enter Name' /> </div> <div data-role='fieldcontain'> <label for='email'>Email ID</label> <input id='email' name='email' type='email' required placeholder...