Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
Only one decimal point in text box validation in java script.Most java script Validation support multiple dot's.please send me
Posted
Updated 8-Mar-17 1:46am

 
Share this answer
 
Try this:
Javascript:
JavaScript
function checkDec(el){
     var ex = /^[0-9]+\.?[0-9]*$/;
     if(ex.test(el.value)==false){
         alert('Incorrect Number');
     }
}

HTML:
ASP.NET
<asp:textbox id="text1" runat="server" onblur="checkDec(this);" />



--Amit
 
Share this answer
 
v2
Put this code in textbox_keypress
here txtweight is my textbox name you use yours


private void txtweight_KeyPress(object sender, KeyPressEventArgs e)
{

if (txtweight.Text.Length == 0)
{
if (e.KeyChar == '.')
{
e.Handled = true;
}
}
if (!char.IsDigit(e.KeyChar) && e.KeyChar != 8 && e.KeyChar != 46)
{
e.Handled = true;
}
if (e.KeyChar == '.' && txtweight.Text.IndexOf('.') > -1)
{
e.Handled = true;
}


}
 
Share this answer
 
Comments
CHill60 8-Mar-17 11:42am    
The question is over 4 years old and already answered. Furthermore the question is tagged ASP.NET. Your "solution" would post back to the server for every keypress in the textbox in the Browser. Not a good solution at all

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900