Today friends we are going to make a simple mobile validation tool using HTML, CSS and JS.
Step 01 :- Create index.html file in VS code and put html code in it.
HTML Code –
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Mobile number validation</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
</head>
<body>
<div>
<form>
<h1 class="text-center">
Validate Your Mobile Number !
</h1>
<div class="input-group">
<input id="mobile" type="text" class="form-control" placeholder="Enter the phone number to check..." />
<div class="input-group-btn">
<button class="btn btn-primary checkmobile" type="button">
Check
</button>
</div>
</div>
</form>
</div>
<script src="script.js"></script>
</body>
</html>
Step 02 :- Create another file and named it style.css
CSS Code –
*{
background-color: #77899c;
}
body {
border-top: 2px solid #007bff;
background: #ffffff;
}
.container {
margin-top: 0.5rem;
}
.container h1 {
color: #00ff6a;
}
.container .input-group input {
border-color: #1b9242;
border-width: 3px;
border-radius: 25px 0 0 25px !important;
width: 5px;
}
.container .input-group .input-group-btn button {
border-radius: 0 25px 25px 0 !important;
}
Step 03 :- Create another file where we put javascript code in and named it script.js
JavaScript Code –
$(document).ready(function() {
$('body').on('click','.checkmobile', function() {
var tdr_regex = /((09|03|07|08|05)+([0-9]{8})b)/g; // Do not use +
var mobile = $('#mobile').val();
if(mobile !==''){
if (tdr_regex.test(mobile) == false)
{
alert( 'Your phone number ' + mobile + ' is not in the correct format!');
}else{
alert( 'Your phone number ' + mobile + ' is valid!');
}
}else{
alert( 'You have not entered your phone number!');
}
});
});
OutPut :-