Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello to all
how can execute this regular expression validator
^[0-9]{0,9}(\.[0-9]{0,3})?$
by java script
i mean write function in java script exec
^[0-9]{0,9}(\.[0-9]{0,3})?$
and this function call by on change event like this
<input type="text" önchange="function name "/>
Posted

Hi
You can use the test() method available in javascript like this:

XML
<script>

function check(Cntrl)
{
var str=Cntrl.value;
//look for "Hello"
var patt=/^[0-9]{0,9}(\.[0-9]{0,3})?$/;

if(patt.test(str))
{
...
}
else
{
...
}
}
</script>


and in the html code:

<input type="text" önchange="check(this)"/> 
 
Share this answer
 
C#
$("#myTextBox").bind("change", function(event) {

        var matches = ($(this).val()).match(/^[0-9]{0,9}(\.[0-9]{0,3})?$/);
    if (matches) {
        //do you logic here
    }else{//do you logic here

}

    });
 
Share this answer
 
XML
<script type="text/javascript">
function checkregex(){
var reg=/^[0-9]{0,9}(\.[0-9]{0,3})?$/;
if (document.myform.myinput.value.search(reg)==-1) //if match failed
alert("Please enter a valid number inside form")
}
</script>

<form name="myform">
<input type="text" name="myinput" size=15>
<input type="button" onClick="checkregex()" value="check">

</form>
 
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