i want to validate a from before submit using jquery in codeigniter but i am confused how to validate a form before submit. I know the validation class in codeigniter but i want validate a form in front end.
Asked
Active
Viewed 1,632 times
-4
-
3[You could have search a bit](http://stackoverflow.com/a/15072147/3778613) – AdrienXL Feb 28 '15 at 09:51
-
http://jqueryvalidation.org/ – Sadikhasan Feb 28 '15 at 09:52
1 Answers
5
I use bootstrap validator for client side validations. Easy to use & understand.
Here's a sample.
<form id="signinForm">
<div class="form-group">
<input type="text" class="form-control" name="username" placeholder="Username" />
</div>
<div class="form-group">
<input type="password" class="form-control" name="password" placeholder="Password" />
</div>
<!-- Do NOT use name="submit" or id="submit" for the Submit button -->
<button type="submit" class="btn btn-default">Sign in</button>
</form>
<script>
$(document).ready(function() {
$('#signinForm').formValidation({
framework: 'bootstrap',
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
username: {
validators: {
notEmpty: {
message: 'The username is required'
},
stringLength: {
min: 6,
max: 30,
message: 'The username must be more than 6 and less than 30 characters long'
},
regexp: {
regexp: /^[a-zA-Z0-9_]+$/,
message: 'The username can only consist of alphabetical, number and underscore'
}
}
},
password: {
validators: {
notEmpty: {
message: 'The password is required'
}
}
}
}
});
});
</script>
Use this link for reference.

version 2
- 1,049
- 3
- 15
- 36