How to validate a decimal value with 2 digits after decimal point (de decimal point is a comma)

 

I am a newbee, I have a Textbox where de user must write the price of an object.

How can I validate de data entry in the Textbox (it must be a valid decimal with 2 digits after decimal point), and my pages are in  Portuguese so the decimal point to be accepted must be a comma

 

thanks

0
bastiaanwilderom
6/30/2008 5:27:30 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

5 Replies
3501 Views

Similar Articles

[PageSpeed] 0

 well you can do something like followig:

 suppose TextBox1.Text = 123456,789

then you can say

if(TextBox1.Text.Contains(",") )

{

    int index1 = TextBox1.Text.IndexOf(",") +1;

    int index2 = TextBox1.Text.IndexOf(",") +2;

  if(index1<TextBox1.Text.Length-1 && index2<TextBox1.Text.Length-1)

{

     Here you can write your logic to check if TextBox1.Text[index1] and TextBox1.Text[index2] are integers

}

 

}

 


Please mark as answer if you find my post helpful.
0
CsharpJunkie
6/30/2008 6:02:30 PM

These may helps 

http://forums.asp.net/p/1254166/2326453.aspx#2326453

http://forums.asp.net/p/1230432/2219248.aspx#2219248 


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
6/30/2008 8:00:27 PM

use regular expression validator and in the validation expression specify this: (^\d*\.\d{2}$)


Thanks,
Ragha
0
RaghaSM
6/30/2008 8:00:59 PM

HI,

I think you should use the Regular expression for you problem. Please see a working example below. Run the example in asp.net and see the results.

 

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TxtAmount" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="ReqAmount" ControlToValidate="TxtAmount" runat="server" ErrorMessage="Amount is required" Display="Dynamic"></asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="RegxAmount" runat="server" ControlToValidate="TxtAmount" ValidationExpression="(^\d*\,\d{2}$)" Display="dynamic" ErrorMessage="Not a valid format. Valid format is 99999,99"></asp:RegularExpressionValidator><br />
        <asp:Button ID="BtnValidate" runat="server" Text ="Validate" />
    </div>
    </form>
</body>
</html>
 
[Please mark the post as answer that helps you.]

Regards,
Farhan Uddin Khan
Enpointe Technologies
0
FarhanK
6/30/2008 8:12:30 PM

 

Thanks Farhank it works
0
bastiaanwilderom
6/30/2008 8:27:10 PM
Reply:

Similar Artilces:

how to convert value with decimal point into value with decimal comma
Hello,  I like to know how I can change (for example) the value 55.55 into 55,55. (The system in my country is using comma's instead of points) I'm starting with  a string with the value "55.55" Then I will convert it to a double 55,55 Do I need the the system.Globalization namespace or is there just a simple solution?               Hi,If you are just going to use this format for display then it would be easy to do this:double dTemp;dTemp = 55.55;Response.Write(dTemp.ToString().Replace(".",","));H...

Validate 2 digits after decimal point?
Hi, I am wondering what is the best approach to be able to validate a numeric field with 2 digits after the decimal point. Does anyone have a small snippet of code. I can't use the inbuilt validator controls of asp.net, as the textboxes would be generated on the fly. Thanks You can add validator controls on the fly, same as any other control.Jared LivingstonMrLivingston.com - Livingston Family WebsiteTest/Demo site - moonmark.com Hi, Thanks for the speedy reply. I am just trying to write this function, to which I pass the name of the textbox, the validation type such ...

2 Decimal point value Problem..
Hi guys, Need help! How to create a DBF table with Floating Point column (2 Decimal Places) in Delphi code? Thanks. Regards, Eric coiner roy wrote: > Hi guys, > > Need help! > How to create a DBF table with Floating Point column (2 Decimal > Places) in Delphi code? Thanks. > > > Regards, > Eric Which Delphi version? Which Database components? No problems with creating other kinds of dbf-tables or columns? Tiedo -- ...

Need to format float with no decimals or decimal point.
Is there a format for float that displays only the integer portion?  Or at the least, integer portion and decimal point but no digits to right? Eval("L_DistCalc", "{0:f}") Thank you, What about this: Eval("L_DistCalc", "{0:f0}")Limno Wow - thanks.  Is there a good reference book that has all the format forms, control structures and properties.  Everything I have has a the essentials but nothing in depth.  I know this kind of thing is simple but is sure is a lot to try and remember. Thank you,  You can sear...

Keeping DBEdit value to 2 decimal point
How can I prevent the DBEdit from accepting more than 2 decimal points? I have a situation that the DBEdit gets an amount like 2.675 and at exit, it gets rounded up to 2.68. We need this to alert the user and not round the amount at exit, or not accept more than 2 decimal points to begin with. Any suggestion is appreciated. what about regular expressions? ^[0-9]*[.,]?[0-9]{0,2}$ I haven't test the expression so you have to find it by your self. > {quote:title=Deborah Sassounian wrote:}{quote} > How can I prevent the DBEdit from accepting more than 2 decimal points? &g...

Web form SaveAs XML decimal point
This is a multipart message in MIME format. --=_alternative 0029B2CEC12574C0_= Content-Type: text/plain; charset="US-ASCII" If I perform SaveAs in XML format and column is not displayed in datawindow decimal point is "," and ImportFile corrupts this number because it supposes probably ".". If column is displayed in dw it is ok (I put this column to report and erase option visible). Is there some other trick ? --=_alternative 0029B2CEC12574C0_= Content-Type: text/html; charset="US-ASCII" <br><font size=2 face="sans-serif&q...

decimal point #2
------=_NextPart_000_001D_01C1A834.21827C90 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Hi, I am trying to move the decimal point 2 places to the the left. Eg : To make 4536233 into 45362.33 I tried this $total = "4536233"; $total = sprintf("%0.2f",$total); print "$total"; But I get this 4536233.00 Can anyone help please Regards Stuart Clark ------=_NextPart_000_001D_01C1A834.21827C90-- Dear Stuart, The Sprintf function may not be able to change the value of the scalar varia...

Decimal point / comma
Hi, We have been stuggeling for some time with a decimal point issue on our windows 2000 workstation. On a em (or dw column) we use an editmask of "#0.00" or "##.00" the em shows 0.00 or .00 during runtime. If we enter 12.15 we get 1215 if we show dec(em.text) in a messagebox. If we change the country for Dutch/Belgium to English/Us, the program works correct, but when we change it back, the problem popsup again. We use powerbuilde 8 build 9100 Andrew Peiman May be you can use String() function with format Messagebox( "Message", String(d...

Decimal point and comma
Hi, I have this problem validating a powerbuilder exported XML file versus and XSD using the XMLParseFile function. I get the following error: Error parsing XML document: Datatype error: Type:InvalidDatatypeValueException, Message:Value '1,00' does not match any member types (of the union) . d:\interfaces\stockmove\out\S17.C2P, Line: 17, Position: 24. The tag in question looks as follows: <qtyVal>1,00</qtyVal> The problem seems to be that a numeric field ( which is part of a union in the XSD because I need it to allow empty values, which can&...

how do i keep a value with 2 integers following a decimal point?
 Hi All.I have a number like 0.50 i.e a value representing money in a double variable.However, it loses the last 0 and i am left with 0.5. I am using the formatCurrency function but still no luck. The problem is when i display the value stored, it only displays at 0.5 not 0.50. Any solutions?Thanks  How many parameters are you passing to FormatCurrency()? The second parameter, which is optional, specifies the number of decimal places to display. I looked here: http://msdn.microsoft.com/en-us/library/3352e6f5(VS.80).aspx Try FormatCurrency(moneyAmount, 2) Hope this helps. EDIT...

CompareValidator fail if currency value more than 2 decimal point
Does anyone encounter problem using the compare validator against a textbox with operator=DataTypeCheck, type="Currency" and the textbox value contains more than 2 decimal point? With type="Double" it works fine with more than 2 decimal point but must not have comma. Below is my test result: Currency 10,200.20 pass Currency 10,200.204 fail Double 10,200.20 fail Double 10200.204 pass Any suggestion to overcome this issue? Leon ...

XSD file Decimal column displays 4 point after decimal
Hi to all,              I have a xsd file with one table adapter, it has 4 column id int name string class string amount decimal i drag and drop the columns into rdlc file but, the report displays 4 digit after decimal point but i want to display it as two decimal point. How to do this experts please help me. But i checked in my query from sql it is displays as it is in the table(there some data have four digit after decimal some data have two digit after decimal) but when get it into DataSet object all data are converted i...

decimal point
------=_NextPart_000_0018_01C1A7FB.403BDF20 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Hi, I am trying to move the decimal point 2 places to the the left. Eg : To make 4536233 into 45362.33 I tried this $total = "4536233"; $total = sprintf("%0.2f",$total); print "$total"; But I get this 4536233.00 Can anyone help please Regards Stuart Clark ------=_NextPart_000_0018_01C1A7FB.403BDF20-- use strict; my $var=4536233; my $new_var=$var/100; print $new_var; Shawn ...

Decimal point
Hi guys, Is there function to get the number after a decimal point? ex: 6.500 I need to get the 500 only Thanks in advance On 27 Jun 2008 09:35:04 -0700, Ramez Nabil wrote: I think you might want to tell everyone where you get the "6.500" from e.g. numeric column etc and who you are trying to get the "500" like stored procedure, dml user, C programmer etc. I think this way you get replies that might better fit your needs. J >Hi guys, >Is there function to get the number after a decimal point? > >ex: 6.500 I need to get the 500 only &g...

Web resources about - How to validate a decimal value with 2 digits after decimal point (de decimal point is a comma) - asp.net.web-forms

Credit Card Validate on the App Store on iTunes
Get Credit Card Validate on the App Store. See screenshots and ratings, and read customer reviews.

Who Is Going to Shoot Obama? Paul Broun Chuckles, Validates Question - YouTube
Republican Congressman from George Paul Broun chuckles and does not even come close to denouncing a question asked by a constituent at a town ...

PM says MH370 debris find 'validates search'
Experts say recovered MH370 debris is consistent the area being searched in the southern Indian Ocean.

Spain's domination of England validates the Socceroos' search for identity
It is incredible to think that with all the billions of dollars of resources in the English game, their solitary success remains almost 50 years ...

Fracking report validates environmental concerns in N.W.T.
... Kenyon of the Pembina Institute. A director of the Pembina Institute in Edmonton says a new report on the risks of shale gas development validates ...

【medical-news】Study First to Validate That Singing Can Help People Learn a Foreign Language - 医药生命科学动态跟踪 ...
只是新闻而已Fernanda Ferreira’s family emigrated from Portugal to Canada when she was very young. There, like most Canadian children, she learned French ...

Supreme court validates private loans for rightful purposes
Supreme court validates private loans for rightful purposes

IXIA : Selected by China Network World to Validate High-Performance Cisco ...
IXIA : Selected by China Network World to Validate High-Performance Cisco ... 4-traders (press release) BEIJING - June 25, 2013 - Ixia (Nasdaq: ...

Apple Watch uses constant skin contact to validate Apple Pay purchases
... will the device make sure payments via Apple Pay are secure? Both the iPhone 6 and iPhone 6 Plus have the convenient Touch ID sensor to validate ...

Like You Really Need To Validate Your Social Media Presence….
How many Fortune 500 companies are blogging and using social media, and what can law firms learn from them?

Resources last updated: 1/19/2016 6:15:57 AM