[<prev] [next>] [day] [month] [year] [list]
Message-ID: <CAFf+5zj2heroGL4cEMRYS9SCkTwDWQh1T9=3ZeDTM9G0aENThQ@mail.gmail.com>
Date: Fri, 30 May 2025 21:27:26 +0530
From: Amit <amitchoudhary0523@...il.com>
To: linux-kernel@...r.kernel.org
Subject: HTML and Javascript code for validating a text field using Javascript
and showing error below the text field if the value entered in the text field
is not valid (Two files: form.html and result.html).
HTML and Javascript code for validating a text field using Javascript
and showing error below the text field if the value entered in the
text field is not valid (Two files: form.html and result.html).
-------------
form.html
-------------
<!DOCTYPE html>
<html>
<head>
<script>
function validateForm() {
var err = document.getElementById("error")
var x = document.forms["myForm"]["phone_num"].value;
var re = /^[0-9]{10}$/
let result = re.test(x)
if (result) {
error.innerHTML = ""
return true
} else {
error.innerHTML = "Please enter a valid phone number."
error.style.color = "red"
return false
}
}
</script>
</head>
<body>
<form name="myForm" action="result.html" onsubmit="return
validateForm()" method="post">
Phone Number (10 digits only): <input type="text" name="phone_num"><br>
<span id="error"></span><br>
<input type="submit" value="Submit">
</form>
--------------
result.html
--------------
Success.
Powered by blists - more mailing lists