i have the following validation on a form field:
$(".controlscard input").blur(function() {
var re = /^(?:[0-9]+[a-z]|[a-z]+[0-9])[a-z0-9]*$/i;
if(re.test(document.getElementById("register_coachcard_no").value))
{
$(this).css('border-color','green');
$(this).siblings('.info').css('display','none');
$(this).siblings('.error').css('display','none');
$(this).siblings('.valid').css('display','inline-block');
$("#email_error40111").hide();
}
else
{
$(this).css('border-color','red');
$(this).siblings('.info').css('display','none');
$(this).siblings('.valid').css('display','none');
$(this).siblings('.error').css('display','inline-block');
$('#registerErrors').show();
$('#email_error40111').remove();
$('#registerErrors').append('<p id="email_error40111">Coachcard must contain at least 1 letter and 1 number</p>');
}});
The above basically checks if the entered content contains 1 letter and 1 number.
I need to put something in place where, if the value length is 8 characters, it will need to check for upto 2 letters, and then 6 numbers.
If the value length is 9 characters, then only numbers can be entered.
Any suggestions on what i can do?
Cheers, Dan
/^[a-zA-Z]\d|[a-zA-Z]{2}\d{6}|\d{9}$/i- Is this what you want?|specifies a logical OR. (1 letter, one number OR two letters, 6 numbers OR 9 numbers).