TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Anilananda Chakrabortty
NA
425
78.5k
Restrict input with regex
Jan 2 2020 11:27 PM
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) {
//alert(validChars);
var
keyChar = String.fromCharCode(event.which || event.keyCode);
//alert(keyChar);
return
validChars.test(keyChar) ? keyChar :
false
;
}
Thanks
Reply
Answers (
2
)
How to add new option if not exist in the list using select2
how can i get bootstrap version logically?