Click here to Skip to main content
15,889,520 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need the javascript function to allow a user to only enter the value in textbox in format 20.00.

If he does not enter in that format, he is given a message.
Posted
Updated 27-Jul-11 23:08pm
v2

 
Share this answer
 
Comments
_Zorro_ 28-Jul-11 4:39am    
+5
walterhevedeich 28-Jul-11 4:46am    
Thank you.
Dalek Dave 28-Jul-11 5:09am    
Good links Walter.
walterhevedeich 28-Jul-11 5:21am    
Thanks Dave.
Please refer to:
http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/MaskedEdit/MaskedEdit.aspx[^]
http://www.eggheadcafe.com/community/aspnet/3/10013006/how-do-i-restrict-the-user-to-only-enter-interger-or-decimal-values.aspx[^]

XML
<form name="form" method="post" onsubmit="return validate();">
Enter Decimal Number:<input type="text" name="num"> <input
type="submit" value="Check">
</form>


Paste the following within you page header tag
C#
<script type="text/javascript" language="javascript">
function isDecimal(str){
if(isNaN(str) || str.indexOf(".")<0){
alert("Invalid");
}
else{
str=parseFloat(str);
alert ("Entered number is decimal")
}
}
function validate(){
var dec=document.form.num.value;
if (dec == ""){
alert("Please enter.");
form.num.focus();
return false;
}
if (isDecimal(dec)==false){
num="";
form.num.focus();
return false;
}
return true;
}
</script>
 
Share this answer
 
v5
Comments
Dalek Dave 28-Jul-11 5:09am    
Nice.
Monjurul Habib 28-Jul-11 5:11am    
thank you.

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