HI,
I have a input requirement of string pattern from front end.
the string can be aa-bbb-cccc the first word would be minimum 2 then second word would be between (3 to 5 character) and the last word can be (4 to 7 character)
each word is separated by a hyphen.
so that i have written one regular expression but it is not working can any one help me.
i am not able to find the problem.
- var CustomeExp=/^([a-zA-z]{2})-([a-zA-Z]{3,5})-([a-zA-Z]{4,7})$/;
- here is my code which...
- <!DOCTYPE html>
- <html>
- <head>
- <script data-require="jquery@*" data-semver="3.2.1" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
- </head>
- <body>
- Enter your text :
- <br>
- <input type="text" onkeypress="return validateKeypress(CustomeExp);">
- </body>
- </html>
JS
- var CustomeExp=/^([a-zA-z]{2})-([a-zA-Z]{3,5})-([a-zA-Z]{4,7})$/;
-
- function validateKeypress(validChars) {
-
- var keyChar = String.fromCharCode(event.which || event.keyCode);
-
- return validChars.test(keyChar) ? keyChar : false;
- }
Thanks