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

<script lang='javascript'>
var isNumeric  = /^(\d*)(\.?)(\d*)$/;

function checknum()
     if (!isNumeric.test(document.frm.txt1.value))
	 alert( 'Not a valid number');
	 return false;
        alert( 'Number Accepted');
	return false;
<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()'>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.