Click to See Complete Forum and Search --> : problem while focusing cursor on textbox after validation


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.

srinika
February 28th, 2007, 10:34 AM
Hi,

U may use the following in the ASPX file

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txt_Phoneno"
ErrorMessage="Please enter a phone number with the format xxx-xxx-xxxx." Style="z-index: 104;
left: 266px; position: absolute; top: 120px" ValidationExpression="\d{3}\-\d{3}\-\d{4}"></asp:RegularExpressionValidator>

instead of ur Javascript

The RegularExpressionValidator, does the hard work for u.