Validate Money Currency format in ASP.Net TextBox using Validators

Last Reply on Jan 08, 2014 08:58 AM By Azim

Posted on Jan 08, 2014 08:50 AM

dear fellas, 

im trying to dcreate a requiredfieldvalidator that only accept amount of money. 

first i used this expresvalidator as it cant receive any letter.

 

<asp:RegularExpressionValidator ID="rvcheckno" runat="server" 
                                                ErrorMessage="Amount receive numbers only!" ControlToValidate="tbamount" 
                                                InitialValue="0" ValidationGroup="number">
                                                </asp:RegularExpressionValidator>

but then it also cant receive cent.

i was trying to do something that can accept 130.00

tq

Posted on Jan 08, 2014 08:56 AM

Try this

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function validate()
{
	    var pattern = /^-?[0-9]+(.[0-9]{1,2})?$/;
            var text = document.getElementById('textbox1').value;
            if (text.match(pattern)==null)
            {
		alert('the format is wrong');
            }
	    else
	    {
		alert('OK');
	    }


}


</script>


</head>
<body style="font-family:Calibri">
<input type='text' id='textbox1' />
<input type='button' value='OK' onclick="validate();">
</body>
</html>

 


Posted on Jan 08, 2014 08:56 AM

Try this

 <asp:TextBox ID="txtAmount" runat="server"></asp:TextBox>
        <asp:RegularExpressionValidator ID="revNumber" runat="server" ControlToValidate="txtAmount"
            ErrorMessage="Please enter only numbers like 100 or 100.00" ValidationExpression="^\d+(\.\d\d)?$"></asp:RegularExpressionValidator>
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" />

 


Posted on Jan 08, 2014 08:58 AM

This Way:

  <asp:TextBox ID="txtAmount" runat="server"></asp:TextBox>
        <asp:RegularExpressionValidator ID="revNumber" runat="server" ControlToValidate="txtAmount"
            ErrorMessage="Only Numbers" ValidationExpression="^\$?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(.[0-9][0-9])?$"></asp:RegularExpressionValidator>

Thank You.

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html