Click to See Complete Forum and Search --> : code requested please
suganya
06-30-2003, 10:06 AM
hi all,
i am very new to this site!...
i would really appreciate it if some1 can help me with the js code for this....?....
i have a text field for which the input mask shld be of the format xx-xxxx-xxxx-x . the first 2 chars could be alpha but the rest shld only be numeric. this text field shld also be able to handle the delete, backspace keys appropriately...
thanks much in advance....
suganya
06-30-2003, 12:00 PM
i do not find any code similar to what i need...any help wud definitely be appreciated.....
thankyou
Charles
06-30-2003, 12:06 PM
<input type="text" onchange="if(!/^\w{2}-\d{4}-\d{4}-\d$/.test(this.value)) {alert('That does not appear to be a valid entry.'); this.value=''; this.focus()}">
Try something like this:
<html>
<head>
<script type="text/javascript">
function validate(frm) {
re = /^\w{2}[-](\d{4}[-]){2}\d{2}$/;
if (!re.test(frm.mytext.value)) {
alert ("That is an invalid entry");
}
}
</script>
</head>
<body>
<form name="form1" method="post" action="" onsubmit="return validate(this);">
<input type="text" name="mytext">(ie. xx-1111-1111-11)
<input type="submit" value="Submit">
</form>
</body>
</html>
Charles -
Your's doesn't allow for two digits at the end of the string.
Did you mean this:
(!/^\w{2}-\d{4}-\d{4}-\d{2}$/.test(this.value)
Charles
06-30-2003, 12:16 PM
Admittedly my eyes are bad and getting worse, but the way I read the request only one trailing digit is required. But just to be sure I'm going to brew up a pot of tippy gold Yunan. That always helps.
lol... know what? It's not you, it's me... :rolleyes: You were right. One digit at the end...
suganya
06-30-2003, 01:32 PM
thanks very much charles and pyro...