nikko50
05-02-2008, 08:01 PM
Hi all. I would like to validate a number a user enters into my form. This number can be 5 or 6 numerical numbers or have 6 numeric numbers seperated by a dash with 6 more numeric numbers like so 123456-123456. How can I do this. I'm stumped on this one. Please help me.
Tracy
tomws
05-02-2008, 08:05 PM
It would be better to show what you've tried up to now so someone can offer some pointers.
nikko50
05-02-2008, 08:21 PM
I actually have nothing. I can validate 5 or 6 numbers but the other one confuses me:(
Tracy
nikko50
05-02-2008, 11:57 PM
Here is what I have so far but it does not work. Can anyone help?
<script>
function validateCharge(theForm){
//VALIDATE CHARGE
if(theForm.charge){
if(!theForm.charge.value.match(/^\d{5}$/) || !theForm.charge.value.match(/^\d{6}$/)){
alert("Please input a valid Charge Account!")
theForm.charge.style.backgroundColor='pink';
theForm.charge.focus();
return false
}}
return (true);
}
</script>
<form method="POST" name="theForm" onsubmit="return validateCharge(theForm)" action="--WEBBOT-SELF--">
<input type="text" name="charge" size="20"></p>
<p><input type="submit" value="Submit" name="B1"></p>
</form>
Trinithis
05-03-2008, 01:15 AM
/\d{5}|\d{6}(?:-\d{6})?/.test(theForm.charge.value)
Philip M
05-03-2008, 08:06 AM
/\d{5}|\d{6}(?:-\d{6})?/.test(theForm.charge.value)
No.
if (/^(\d{5,6})$|^(\d{6}-\d{6})$/.test(theForm.charge.value)) {
James (007) Bond: (to Bibi) "You get your clothes back on, and I'll buy you an ice cream."