Javascript Validation - Webmasters - Nairaland
Nairaland Forum › Science/Technology › Webmasters › Javascript Validation (662 Views)
| Javascript Validation by akereconfi(op): 2:03am On Nov 18, 2014 |
Hello, please I need a helping hand on JavaScript validation on checking for numbers in a text field. Have tried w3school but got only validation for email Thanks for your contribution |
| Re: Javascript Validation by Craigston: 3:18am On Nov 18, 2014 |
akereconfi:Uh, what's your code so far? |
| Re: Javascript Validation by akereconfi(op): 3:34am On Nov 18, 2014 |
Craigston:<script> function validateForm() { var x = document.forms["myForm"]["fname"].value; if (x==null || x=="" {alert("First name must be filled out" ;return false; } } </script> </head> <body> <form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post"> First name: <input type="text" name="fname"> <input type="submit" value="Submit"> </form> </body> |
| Re: Javascript Validation by Craigston: 3:57am On Nov 18, 2014 |
akereconfi:You said you want to check for number in the string. What would you like to do if a number is found? You can use 'parseInt()' or 'parseFloat()' here. if (parseInt(x) != "" {do something}; |
| Re: Javascript Validation by Craigston: 3:58am On Nov 18, 2014 |
akereconfi:You said you want to check for number in the string. What would you like to do if a number is found? You can use 'parseInt()' or 'parseFloat()' here. if (parseInt(x) != "" ) {do something}; |
Comment Box Validation (urgent) • Form Validation Tutorial Using Javascript, Php, Ajax • Form Validation Tutorial Using Javascript, Php And Ajax! • 2 • 3 • 4
Web Design And Logo Branding Is Now Affordable For You (christmas Offer). • Cheap Reseller Hosting With Cpanel Starts At $5.90/mo • Click My Adsense Ads And I'd Click Yours
{