Click here to Skip to main content
15,843,070 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
  <div class="row">
   <div class="medium-6 columns">
  Current Interest (APR) that you pay
  <asp:RegularExpressionValidator ID="rgv2"
           ControlToValidate="txtCurrentInterest" runat="server"
           ErrorMessage="Interest be in numbers" ValidationGroup="vgSubmit"
           ValidationExpression="^\d+%?$">*</asp:RegularExpressionValidator>

  <asp:RequiredFieldValidator ID="rv6" runat="server" ControlToValidate="txtCurrentInterest" ErrorMessage="Current Interest is Required" ValidationGroup="vgSubmit">*</asp:RequiredFieldValidator>
    <asp:TextBox ID="txtCurrentInterest" runat="server"></asp:TextBox>
   </div>
</div>


What I have tried:

i want to get interest value from users through asp.net textbox. it accepts numbers and optional to enter "%" only. prohibit to enter any other special characters or any alphabet letters.
Posted
Updated 27-Jun-19 0:54am
Comments
OriginalGriff 27-Jun-19 1:30am    
And?
What happens that you didn't expect or doesn't happen that you did?
What did you do to make that happen?
What have you tried to fix it?
Where are you stuck?
What help do you need?

Use the "Improve question" widget to edit your question and provide better information.
Member 13596072 27-Jun-19 2:52am    
my regular expression equation doesn't work it block "%" also
OriginalGriff 27-Jun-19 3:32am    
What do you mean, exactly?
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.

Your regex as shown will allow "1", "12", "1%", "12%", and so on - but not "%" on it's own. So what - exactly - did you expect it to do?
Member 13596072 27-Jun-19 5:44am    
i need to allow like 13.52% or 13.52 or 1.3 or 1.3%
Patrice T 27-Jun-19 6:05am    
Use Improve question to update your question.
So that everyone can pay attention to this information.

Quote:
Regular expression to validate interest that get from user.it need only to allow only one specific special character(%) and numbers

Beware, loan interests are usually non integers 2.4%
You should give examples of what is valid input and what is not, bacause your RegEx look Ok to me.

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx: Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
This site also show the Regex in a nice graph but can't test what match the RegEx: Regexper[^]
 
Share this answer
 
Quote:
i need to allow like 13.52% or 13.52 or 1.3 or 1.3%
Then you need to tell us that, don't you! We really can't read your mind...
Try:
^(\d+(\.\d+)?)%?$


If you want to use Regular Expressions, then get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
 
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