-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
jQuery 2.0 Development Cookbook
By :
When collecting data from a user, there are many situations when you will want to only allow numbers in a form field. Examples of this could be telephone numbers, PIN codes, or ZIP codes, to name a few. This recipe will show you how to validate the telephone number field within the form we created in the previous recipe.
Ensure that you have completed the previous recipe and have the same files available. Open validation.js in your text editor or IDE of choice.
Add number validation to the form you created in the previous recipe by performing the following steps:
Update validation.js to be as follows, adding the valdiateNumber() function with an additional hasClass('number') check inside the for loop:
$(function(){
$('.submit-btn').click(function(event){
//Prevent form submission
event.preventDefault();
var inputs = $('input');
var isError = false;
//Remove old errors
$('.input-frame').removeClass('error...
Change the font size
Change margin width
Change background colour