HTML text box should only accept numbers and dot

Author - Kailash

You can use the following javascript code to check textbox value:

<html>
<head>
<script language="Javascript">
function isNumberKey(evt)
{
var re=new RegExp(/^[0-9]*.?[0-9]*$/);
if(document.getElementById("text").value.match(re))
{
alert("match");
}
else
{
alert("no match");
return false;
}
}
</script>
</head>
<body>
<input id="text" type="text" value="0" name="text" >
<button id="b1" onclick="return isNumberKey(event)" name="btn" type="submit">Save
</html>

Webner Solutions is a Software Development company focused on developing CRM apps (Salesforce, Zoho), LMS Apps (Moodle/Totara), Websites and Mobile apps. If you need Web development or any other software development assistance please contact us at webdevelopment@webners.com

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *

Send your message