Copyright © 2009 RichoSoft All rights reserved. Made By RichoSoft.  Terms of use | Privacy policy
Welcome.All Resources.Page Counters.Tips & Tricks Menu.Contact us.My Account.Site Map.
Welcome.All Resources.Page Counters.Tips & Tricks Menu.Contact us.My Account.Site Map.
Tips & Tricks
Here are some more useful Java Scripts
Validating a Number in a Range

Want to ensure that the user enters a number within a certain range in a text box on a form?
Enter a number in the box above and click Submit to try it. If you enter a correct value the response in this example will post the data back to this form.  
Here’s how to do it.

In your code for the Input Box add :
onBlur="if ((this.value != this.defaultValue) && (isNaN(this.value) || (parseFloat(this.value) > 300) || (parseInt(this.value,10) < 200))) alert ('You must enter a number between 200 and 300.');"
(In this example we want a number between 200 an 300)

eg:
<input type="text" name="Bnum" onBlur="if ((this.value != this.defaultValue) && (isNaN(this.value) || (parseFloat(this.value) > 300) || (parseInt(this.value,10) < 200))) alert ('You must enter a number between 200 and 300.');">

In the sample above we have also added  form validation to ensure boxes are not blank.
Total Form Validation examples are available to members only. (Register and Log On to learn more.)
Email Validation

Want to check if a valid email address has been entered? This is a very simple basic checking script, for a more sophisticated and thorough checking script you will need to Register and Log In as it is for members only.
Enter an invalid email in the box above and click submit to try it. If you enter a valid email the form will be submitted (In this example back to this page.)
Here’s how to do it.

In your code for the Input Box add :
onBlur="if ((this.value != this.defaultValue) && ((this.value.indexOf('@') == -1) || (this.value.lastIndexOf('.') < this.value.indexOf('@')))) alert('You must enter a valid email address.');"

eg:
Email address: <input type="text" name="fEmail" onBlur="if ((this.value != this.defaultValue) && ((this.value.indexOf('@') == -1) || (this.value.lastIndexOf('.') < this.value.indexOf('@')))) alert('You must enter a valid email address.');">

In the sample above we have also added  form validation to ensure boxes are not blank.
Total Form Validation examples are available to members only. (Register and Log On to learn more.)
Enter a Number
Email Address
More Tips & Tricks
Tips & Tricks Page 3