canuhelpme
February 24th, 2007, 07:29 AM
I am validating a phoneno in textbox.If the phone no is invalid i will display a messagebox specifying error.On clicking ok on the message box i need to focus the cursor in the phoneno field.I have done this.But a problem occurs that when the user enters an invalid number(Previously tried numbers) by pressing the down arrow key and clicks the mouse on next textbox that invalid number will be accepted without the message box display.If i enter the same number again it will be accepted?What is the solution?
my code is as follows (javascript)
function
FormValidate()
{
if(document.WO_form.txt_Phoneno.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1)
{
alert(
"Invalid phone number.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.");
document.getElementById(
"txt_Phoneno").focus();
document.getElementById(
"txt_Phoneno").value=""; /* clearing previously entered error value*/
}
}
i am calling javascript from ontextchanged event.
my code is as follows (javascript)
function
FormValidate()
{
if(document.WO_form.txt_Phoneno.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1)
{
alert(
"Invalid phone number.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.");
document.getElementById(
"txt_Phoneno").focus();
document.getElementById(
"txt_Phoneno").value=""; /* clearing previously entered error value*/
}
}
i am calling javascript from ontextchanged event.