0% found this document useful (0 votes)
6 views

Java

The document contains a JavaScript form validation function that validates form fields on submission. The function checks if fields are empty, validates email and phone number formats, and checks password length.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Java

The document contains a JavaScript form validation function that validates form fields on submission. The function checks if fields are empty, validates email and phone number formats, and checks password length.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

html>

<head>

<title> formvalidation</title>

<script type="text/javascript">

function formValidate() {

var username=document.forms["registration"]["username"].value;

var email=document.forms["registration"]["email"].value;

var phoneno=document.forms["registration"]["phoneno"].value;

var password=document.forms["registration"]["password"].value;

if (username == "" || email == "" || phoneno == "" || password == "" ){

alert("all fields are empty");

return false;

var ra= /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

if(!ra.test(email)){

alert("invalid email format");

return false;

var re=/^\d{10}$/;

if (!re.test(phoneno)){

alert("invlaid phone number");

return false;

if(password.length<6){

alert("invalid password because password must be greater than 6.");

return false;

alert("registration successfull");

return true;

</script>
</head>

<body>

<h1> FORM VALIDATION</h1>

<form name="registration" onsubmit="return formValidate()">

username:<input type="text" name="username"><br><br>

email:<input type="text" name="email"><br><br>

phoneno:<input type="number" name="phoneno"><br><br>

password:<input type="password" name="password"><br><br>

<label for="gender">gender:</label><br>

<input type="radio" id="male" name="gender" value="male">

<label for="gender">male:</label><br>

<input type="radio" id="female" name="gender" value="female">

<label for="gender">female:</label><br><br>

<label for="interest">interest:</label><br>

<input type="checkbox" id="interest" name="music" value="interest">

<label for="interest">music:</label><br>

<input type="checkbox" id="interest" name="sports" value="interest">

<label for="interests">sports:</label><br>

<input type="checkbox" id="interest" name="cooking" value="interest">

<label for="interests">cooking:</label><br>

<input type="submit" value="register">

</form>

</body>

</html>

You might also like