Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression for name field in javascript validation [closed]

Tags:

javascript

i need a regular expression in javascript validation. Regular expression for name field that will accept alphabets and only space character between words and total characters in the field should be in between 2 and 30. i.e., the field should accept min 2 chars and max of 30 chars

like image 737
user1179752 Avatar asked Dec 30 '12 06:12

user1179752


2 Answers

function validate(id) {
    var regex = /^[a-zA-Z ]{2,30}$/;
    var ctrl =  document.getElemetnById(id);
    return regex.test(ctrl.value);
}
like image 198
Adeel Ahmed Avatar answered Oct 06 '22 00:10

Adeel Ahmed


Try this:

/^([a-zA-Z ]){2,30}$/
like image 26
skub Avatar answered Oct 06 '22 00:10

skub