Regex-Validation Which allow only Digits & Hyphen
By Goniey N (Mr. G)
How to Validate The User's Input & Only Allow Digits & Hyphen In One Of The Following Format :
i) ###
ii) ###-###
It Will Not Allow Following Format :
i) -
ii) -###
iii) ###-
iv) -###-
<script type="text/javascript">
function Check(UserInput)
{
var objRegex = /(^[0-9]+[-]*[0-9]+$)/;
if(objRegex.test(UserInput) == true)
{
//Write Here Your Logic...
alert("Match Criteria");
}
else
{
alert("Please Enter Only Digits & Hyphen.");
}
}
</script>
<FORM name="windowEvent">
Enter Your Value : <input type="text" name="txtnumber" />
<input type="button" value="Check" name="btnNumber" onClick="Check(txtnumber.value)" />
</FORM>
Regex-Validation Which allow only Digits & Hyphen (3137 Views)