Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

 
Share this answer
 
HTML
<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})%$
 
Share this answer
 
v2

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