Bootstrap 5 Form with Password Validation using jQuery
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 5 Form with Password Validation using jQuery</title>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.1/css/bootstrap.min.css'>
<script src='https://code.jquery.com/jquery-3.6.0.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.3/jquery.validate.min.js'></script>
</head>
<body>
<div class='container mt-5'>
<form id='myForm' method='POST'>
<div class='form-group'>
<label for='password'>Password:</label>
<input type='password' class='form-control' id='password' name='password' placeholder='Enter Password'>
</div>
<button type='submit' class='btn btn-primary'>Submit</button>
</form>
</div>
<pre><code><script>
$(document).ready(function(){
$('#myForm').validate({
rules:{
password:{
required:true,
minlength:6
}
},
messages:{
password:{
required:'Please enter Password',
minlength:'Password should be at least 6 characters long'
}
},
submitHandler: function(form) {
alert('Form submitted successfully!');
form.submit();
}
});
});
</script>
</code></pre>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/nnkq 著作权归作者所有。请勿转载和采集!