₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,327,357 members, 8,430,626 topics. Date: Saturday, 20 June 2026 at 07:24 PM

Toggle theme

Javascript Validation - Webmasters - Nairaland

Nairaland ForumScience/TechnologyWebmastersJavascript Validation (665 Views)

1 Reply (Go Down)

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:
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
Uh, what's your code so far?
Re: Javascript Validation by akereconfi(op): 3:34am On Nov 18, 2014
Craigston:
Uh, what's your code so far?
<script>
function validateForm() {
var x = document.forms["myForm"]["fname"].value;
if (x==null || x==""wink {
alert("First name must be filled out"wink;
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:
<script>
function validateForm() {
var x = document.forms["myForm"]["fname"].value;
if (x==null || x==""wink {
alert("First name must be filled out"wink;
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>
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) != ""wink {do something};
Re: Javascript Validation by Craigston: 3:58am On Nov 18, 2014
akereconfi:
<script>
function validateForm() {
var x = document.forms["myForm"]["fname"].value;
if (x==null || x==""wink {
alert("First name must be filled out"wink;
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>
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};
1 Reply

Comment Box Validation (urgent)Form Validation Tutorial Using Javascript, Php, AjaxForm Validation Tutorial Using Javascript, Php And Ajax!234

Would You Do This????How Do I Bypass The Hotspot FirewallCash Pulling Referral Program