Javascript Regex validator for specific condition -


i need javascript regex validator can full fill following condition.

  1. string should contain alphabets , space only.
  2. first character must alphabetic (lowercase or uppercase).
  3. space allowed not mandatory.
  4. space should not repeated. there can multiple space in string.
  5. 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

Popular posts from this blog

java - Null response to php query in android, even though php works properly -

node.js - Using Node without global install -

php - CakePHP HttpSockets send array of paramms -