Click here to Skip to main content
11,483,983 members (70,643 online)
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 7: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 Sergey Alexandrovich Kryukov 210
1 Frankie-C 155
2 Raje_ 155
3 OriginalGriff 147
4 Maciej Los 110
0 Sergey Alexandrovich Kryukov 8,489
1 OriginalGriff 7,943
2 Sascha Lefèvre 3,114
3 Maciej Los 2,581
4 Richard Deeming 2,370


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