Click here to Skip to main content
15,905,419 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hii,
I want to do data type check .. value entered in text box must be in double format. I can use it compare validator for that . but i want to do it using jquery .
Posted

Hi,

You can use Javascript's parsefloat() function to validate the textbox.

http://www.w3schools.com/jsref/jsref_parseFloat.asp[^]

You can try something like this...
Please don't copy and paste, I'm giving you the hint...
JavaScript
$('#txtdouble').blur( function(){
var str= parsefloat($('#txtdouble').val());
if(str==NaN)
{
//do something
}
else
{
//do something
}

});
 
Share this answer
 
Comments
Thomas Daniels 20-Aug-13 3:57am    
Hi,
You posted a link to W3Schools. In my opinion, that's not a good idea. If you want to know why, have a look here: http://www.w3fools.com/[^]
For that you can use jQuery Validation Plugin

Documentation :http://jqueryvalidation.org/documentation[^]

number method

http://jqueryvalidation.org/number-method[^]

Sample

XML
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Makes "field" required and a decimal number only.</title>
<link rel="stylesheet" href="http://jquery.bassistance.de/validate/demo/site-demos.css">

</head>
<body>
<form id="myform">
<label for="field">Required, decimal number: </label>
<input class="left" id="field" name="field">
<br/>
<input type="submit" value="Validate!">
</form>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://jquery.bassistance.de/validate/jquery.validate.js"></script>
<script src="http://jquery.bassistance.de/validate/additional-methods.js"></script>
<script>
// just for the demos, avoids form submit
jQuery.validator.setDefaults({
  debug: true,
  success: "valid"
});
$( "#myform" ).validate({
  rules: {
    field: {
      required: true,
      number: true
    }
  }
});
</script>
</body>
</html>


I hope this will help to you.
 
Share this answer
 
v2

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