Click here to Skip to main content
15,918,268 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi


i had the problem with the regex validation ,
i need enter the value in the dollers format like "$9999.99",only numbers and the doller symbol should be appered


basically i had tried but no use use because , iam not able to catch this formate so please help me this

my sample code is asp.net

but its working for the numerics and not for the doller symbol and ,it was allowing only 4 numbers only ,
this is the sample code
<asp:RegularExpressionValidator runat="server" id="rexNumber" controltovalidate="txtNumber" validationexpression="^[0-9]{4}$"  errormessage="Please enter a 4 digit number!" />


please help me
Posted

Try:
validationexpression="^\$\d{4}\.\d\d$"



"can you explain the the expression so i can modifiy, because it should allow the symbol and numeric but thers is no rules to be in four digits before the decimal point, any way thanks alot , try to explain it"
It's very similar to yours:
^   Start of string
\$  A dollar sign
\d  A digit
{4} Previous object (in this case a digit) exactly 4 instances
\.  A decimal point
\d  A digit
\d  A digit
$   End of string


Get a copy of Expresso[^] - it's free, it explains Regexes and help you to build and test them. I wish I'd written it!
 
Share this answer
 
v2
Comments
[no name] 30-May-11 6:15am    
can you explain the the expression so i can modifiy, because it should allow the symbol and numeric but thers is no rules to be in four digits before the decimal point, any way thanks alot , try to explain it
OriginalGriff 30-May-11 6:25am    
Answer updated
Sergey Alexandrovich Kryukov 30-May-11 12:43pm    
You got patience! My 5.
--SA
check this

^\$?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$

This will handle below formats

-12000

-12,000

-12000.50

-12,000.50

-12,000,000

-12,000,000.50

-$12000

-$12,000

-$12,000.50

-$12,000,000

-$12,000,000.50
 
Share this answer
 
Try this,

ValidationExpression="^\$(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$"
 
Share this answer
 

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