Iam pretty new to regular expressions .I would like to prevent the user from entering in
String data using javascript function with the following condition .
Same sequence of characters cannot be repeated two or more times
aabhi - is allowed
aabbcc - is allowed
dayday - not allowed
abab - not allowed
ababab - not allowed
aaaa - not allowed
this applies to numbers too .Can someone help me with this ? Thanks in advance
Based on your inputs you can use this regex:
/(\w{2,})(\1)/
Code:
re = /(\w{2,})(\1)/;
s = 'dayday';
if (re.test(s))
console.log("invalid);
else
console.log("valid);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.