I need a javascript code the validates 12 numeric charater before decimal point followed by 3 numeri

Posted by Mahendrabasutkar under JavaScript on 10/20/2011 | Points: 10 | Views : 1019 | Status : [Member] | Replies : 1
Hi All,

I need a javascript code the validates 12 numeric charater before decimal point followed by 3 numeric digits


Thanks&Regards
Mahendra




Responses

Posted by: Ndebata on: 10/20/2011 [Member] Starter | Points: 25

Up
0
Down
Try to use regular expression
[0-9]{12}.[0-9]{3}

Javascript
<script type="text/javascript" language="javascript">

function _val(txt) {
var _reg = new RegExp("^[0-9]{12}.[0-9]{3}$");
if (_reg.test(txt.value))
txt.style.cssText = "background-color:green";
else
txt.style.cssText = "background-color:red";
}
</script>

For testing this i have called this in onblur of textbox
<asp:TextBox ID="TextBox1" onblur="javascript:_val(this)" runat="server"></asp:TextBox>





Mahendrabasutkar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response