I have setup jQuery validation on form, The validation currently tests that the telephone number field isn’t empty and is a number, but I’d like it to be able to handle a user placing a space after the mobile/area code.
Can anyone advise what i’d need to do to allow this?
This is my current code –
if((phone.length == 0) || (names == 'Please Enter Your Contact Number (no space)')){
var error = true;
$('.error').fadeIn(500);
$('.pStar').fadeIn(500);
}else{
var value = $('#phone').val().replace(/^\s\s*/, '').replace(/\s\s*$/, '');
var intRegex = /^\d+$/;
if(!intRegex.test(value)) {
var error = true;
$('.error').fadeIn(500);
$('.pStar').fadeIn(500);
} else{
$('.pStar').fadeOut(500);
}
}
I would highly recommend using jQuery validate rather than re-inventing the wheel
a quick google search for uk numbers with jquery validate turned this up
filters
that looks like this