Click here to Skip to main content
13,193,442 members (40,971 online)
Rate this:
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 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 22-Jan-13 23:46pm
Updated 23-Jan-13 8:04am
BC @ CV2.6K
Member 9644686 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 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 23-Jan-13 7:30am
use regular expresn or just read input of textbox along with event and throw alert accordingly..
aravindnass 23-Jan-13 10:52am
can u give me regular expression for this

1 solution

Rate this: bad
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."
                                    ValidationExpression="^[0-9]*\.?[0-9]*$" />

also go through following link's for custom regular expression validator....[^][^]
Validation with Regular Expressions Made Simple[^]
aravindnass 24-Jan-13 3:06am
but it also allowed single . without entering any digits....
Pallavi waikar 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]*$" ValidationExpression

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171018.2 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2017
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