【发布时间】:2015-02-28 09:47:45
【问题描述】:
我想在 codeigniter 中使用 jquery 在提交之前验证来自,但我很困惑如何在提交之前验证表单。 我知道 codeigniter 中的验证类,但我想在前端验证一个表单。
【问题讨论】:
标签: jquery forms codeigniter client-side-validation
我想在 codeigniter 中使用 jquery 在提交之前验证来自,但我很困惑如何在提交之前验证表单。 我知道 codeigniter 中的验证类,但我想在前端验证一个表单。
【问题讨论】:
标签: jquery forms codeigniter client-side-validation
我使用引导验证器进行客户端验证。易于使用和理解。
这是一个示例。
<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>
将此link 用作参考。
【讨论】: