0

Hi all,

I have an input box that should only contain decimal point numbers (including negative values), but I'm not sure how to remove invalid characters and replace it with something that is valid (i.e. the value e3.45 should be replaced with 3.45). If all the characters in the textbox are not valid, then a zero should be input as the value.

Working with regular expressions is not my strong point, so any help would be greatly appreciated, even if it's just helping me onto the right track.

Thanks in advance

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by urtrivedi
0
<html>
<head>
<script lang='javascript'>
var isNumeric  = /^(\d*)(\.?)(\d*)$/;

function checknum()
{
     if (!isNumeric.test(document.frm.txt1.value))
     {
	 alert( 'Not a valid number');
	 return false;
     }
     else
     {
        alert( 'Number Accepted');
	return false;
     }
}
</script>
</head>
<body>
<form name=frm id=frm action='#' method=post>
<input type=text name=txt1 id=txt1>
<input type=button name=btn1 id=btn1 value=check onclick='javascript:checknum()'>
</form>
</body>
</html>

Edited by urtrivedi: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.