Reputation: 53
I need to make a regular expression that allows strings that contain at least one space and that the total of the string is less than 16
At this point, I just got a regexp to allow strings which allow A-Za-z and spaces with 16 maximum but that gives me correct even when the string hasn't got spaces.
/^[\s\S]{0,16}$/;
Upvotes: 0
Views: 336
Reputation: 133458
Based on your shown samples, could you please try following.
^(?=\S*\s)[\sa-zA-Z]{1,16}$
Explanation: Using positive look ahead to check if values other spaces coming 1 or more time followed by a space. Then using character class for space alphabets which will have 1 to 16 occurrences till end.
Upvotes: 2