Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET2.0
if i enter more than 2 digits it should not accept and textbox should surely contains % symbol...example:99%...should be in this format
Posted 2-Jan-13 6:53am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

<html>
<head>
<meta charset="UTF-8">
<title>ssn Checker</title>
<script type="text/javascript">
var Pattern= (\d+(\.\d+)?%);
 
function checkPercentage(Percentage){
    if (Pattern.test(Percentage)) {
        alert("VALID Percentage");
    } else {
        alert("INVALID Percentage");
    }
}
</script>
</meta></head>
<body>
    <form  önsubmit="return false;">
        <input type="text" name="Percentage" size="20">
        <input type="button" value="Check">
            onclick="checkPercentage(this.form.Percentage.value);">
    </input></input></form>
</body>
</html>
 
Second way, You can use Dotnet validation control(regular expression). Define your regex expression in the properties and Customize it as per your requirement.
 
Regular expression for your query:
(\d+(\.\d+)?%)
^0*(100\.00|[0-9]?[0-9]\.[0-9]{2})%$
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 751
1 George Jonsson 330
2 Garth J Lancaster 290
3 Sergey Alexandrovich Kryukov 274
4 BillWoodruff 252
0 Sergey Alexandrovich Kryukov 10,879
1 OriginalGriff 5,555
2 Maciej Los 5,534
3 CPallini 3,819
4 BillWoodruff 3,594


Advertise | Privacy | Mobile
Web04 | 2.8.141030.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2014
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