Javascript Regex validator for specific condition -
i need javascript regex validator can full fill following condition.
- string should contain alphabets , space only.
- first character must alphabetic (lowercase or uppercase).
- space allowed not mandatory.
- space should not repeated. there can multiple space in string.
- last character must alphabetic (lowercase or uppercase).
thanks in advance.
you can try one:
var re = /^(?:[a-za-z]+\s)*[a-za-z]+$/ re.test('a') // true re.test('ab') // true re.test('a b') // true re.test('a b c') // true re.test('a b') // false re.test('ab ') // false re.test(' ab') // false re.test('ab1') // false
Comments
Post a Comment