Untitled
unknown
plain_text
2 years ago
2.0 kB
7
Indexable
$(document).ready(function() {
// Validate Full Name
$('#fullname').on('input', function() {
var fullname = $(this).val();
if (fullname.length > 50) {
$(this).addClass('error');
} else {
$(this).removeClass('error');
}
});
// Validate Username
$('#username').on('input', function() {
var username = $(this).val();
if (username.length > 20) {
$(this).addClass('error');
} else {
$(this).removeClass('error');
}
});
// Validate Mobile Number
$('#mobile').on('input', function() {
var mobile = $(this).val();
if (!/^0[1-9][0-9]{8}$/.test(mobile)) {
$(this).addClass('error');
} else {
$(this).removeClass('error');
}
});
// Validate Email
$('#email').on('input', function() {
var email = $(this).val();
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
$(this).addClass('error');
} else {
$(this).removeClass('error');
}
});
// Validate Address
$('#address').on('input', function() {
var address = $(this).val();
if (address.length > 50) {
$(this).addClass('error');
} else {
$(this).removeClass('error');
}
});
// Validate Date of Birth
$('#dob').on('change', function() {
var dob = new Date($(this).val());
var now = new Date();
if (dob >= now) {
$(this).addClass('error');
} else {
$(this).removeClass('error');
}
});
});
function validateForm() {
var isValid = true;
$('.form-input').each(function() {
if ($(this).hasClass('error')) {
isValid = false;
return false; // Stop iteration
}
});
return isValid;
}
Editor is loading...