hi all,
i'm ''trying'' to validate a phone number using a regular expression in js.
The code is below, but i have a problem. The code works to the extent that it knows when the telephone number is wrong, but when i type the correct format ie - 01222000111 it just clears the field.
Any ideas???
Here's the javascript:
re = /^(\s*\(?0\d{5}\)?\s*\d{6}\s*)|(\s*\(?0\d{3}\)?\s*\d{3}\s*\d{4}\s*)/
function validateForm(form) {
validPhone = re.exec(form.phone.value)
if (validPhone) {
form.phone.value = ""
}
else {
alert(form.phone.value + " isn't a valid number")
form.phone.focus()
}
return false;
}
and the html:
<form method="post" action="" onsubmit="return validateForm(this)">
<input name="phone" type="text" size="50" />
<input type="reset" /> <input type="submit" value="submit" />
</form>
many thanks
c
i'm ''trying'' to validate a phone number using a regular expression in js.
The code is below, but i have a problem. The code works to the extent that it knows when the telephone number is wrong, but when i type the correct format ie - 01222000111 it just clears the field.
Any ideas???
Here's the javascript:
re = /^(\s*\(?0\d{5}\)?\s*\d{6}\s*)|(\s*\(?0\d{3}\)?\s*\d{3}\s*\d{4}\s*)/
function validateForm(form) {
validPhone = re.exec(form.phone.value)
if (validPhone) {
form.phone.value = ""
}
else {
alert(form.phone.value + " isn't a valid number")
form.phone.focus()
}
return false;
}
and the html:
<form method="post" action="" onsubmit="return validateForm(this)">
<input name="phone" type="text" size="50" />
<input type="reset" /> <input type="submit" value="submit" />
</form>
many thanks
c