Experiment No 12

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

EXPERIMENT NO.

12
Design a web page with 2 textboxes to accept name and mobile number from user.
Validate both the form field values using regular expressions.
CODE:
<!--
Aniket Gholap
30
EXP 12
-->
<!DOCTYPE html>
<html>
<head>
<title> Regular Expressions </title>
</head>
<body>
<div class = “container-form”>
<form action = “ ” name = “frm1”>
<label for = “name” id = “name”> Name </label>
<input type = “text” placeholder = “John” id = “name-of-
person” maxlength = “30”> <br> <br>
<label for = “mo-no” id = “mobile”> Mobile Number
</label>
<input type = “text” placeholder = “XXXXXX2451” id =
“mobile-number” maxlength = “10”> <br> <br>
<input type = “button” value = “Submit” id = “form-submit”
onclick = “validate()”>
</form>
</div>

<script>
function validate() {
var name = document.getElementById(“name-of-
person”).value;
var regex1 = /^[a-zA-Z ]{1,30}$/;

if (regex1.test(name)) {
alert(“Valid Name”);
} else {
alert(“Invalid Name”);
}

var number = document.getElementById(“mobile”).value;


var reger2 = /^[7-9][0-9]{2,10}$/;

if (regex2.test(number)) {
alert(“Valid Number”);
} else {
alert(“Invalid Number”);
}
}
</script>
</body>
</html>
--------------------------------------------------------------------------------------------------------
OUTPUT:
As Invalid Inputs As Valid Inputs

--------------------------------------------------------------------------------------------------------

You might also like