Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
heyyy ...I have to validate the numeric and dot and backspace also validate single dot enter...(ie. enter dot(.) only without entering other digits)
 
but my code is allowed '.' dot ...here is my code..and tell how can I validate the dot(.) in textbox
 
<asp:TextBox ID="textPaid" runat="server" onkeypress="return isNumberKeynew(event)"
                                            oncopy="return false" onpaste="return false" oncut="return false" ondragstart="return false" ondrop="return false" AutoComplete="off" attr-identity="PaidAmount"
                                         MaxLength="7" CssClass="textboxForBill1"></asp:TextBox>
 

 

 
function isNumberKeynew(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode;
         if (charCode != 46 && charCode > 31
           && (charCode < 48 || charCode > 57))
            return false;
 
         return true;
      }
Posted 23-Jan-13 0:46am
Edited 23-Jan-13 9:04am
BC @ CV2.6K
v3
Comments
Member 9644686 at 23-Jan-13 6:09am
   
can u tell me u want to allows dot,backspace,numeric in ur textbox not anothers
is it write.
aravindnass at 23-Jan-13 6:23am
   
yes...the above javascript is to allow this ...but my problem is the javascript allows single . (dot)..(so textbox accepts single '.' without entering any values)
 
Eg: 12.22 - valid
. - invalid
shabari7 at 23-Jan-13 7:30am
   
use regular expresn or just read input of textbox along with event and throw alert accordingly..
aravindnass at 23-Jan-13 10:52am
   
can u give me regular expression for this

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

try this code.....
<asp:TextBox ID="textPaid" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="regexpName" runat="server"
                                    ErrorMessage="This expression does not validate."
                                    ControlToValidate="textPaid"
                                    ValidationExpression="^[0-9]*\.?[0-9]*$" />
 
also go through following link's for custom regular expression validator....
http://msdn.microsoft.com/en-us/library/ff650303.aspx[^]
http://msdn.microsoft.com/en-us/library/ms972966.aspx[^]
Validation with Regular Expressions Made Simple[^]
  Permalink  
Comments
aravindnass at 24-Jan-13 3:06am
   
but it also allowed single . without entering any digits....
Pallavi waikar at 24-Jan-13 9:18am
   
is this validation is for decimal value...then only u have to do is remove ? from expression...... ? mean's dot is may required or not in i/p...i.e it allow both single and decimal values..use "^[0-9]*\.[0-9]*$" .....in ValidationExpression

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

  Print Answers RSS
0 Mathew Soji 330
1 BillWoodruff 260
2 Sergey Alexandrovich Kryukov 240
3 OriginalGriff 216
4 Afzaal Ahmad Zeeshan 208
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,028
3 Manas Bhardwaj 4,539
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100