question about jQuery inline form validation
Here is a link on jQuery inline form validation that I'm trying to use http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/
Everything looks good but I have a small problem
I开发者_开发知识库 have an input where I use this kind of validation
'validate[length[6,15]]'
It checks if number of length of input value and if it is less then 6 or grater then 15 gives and error.
Now what I want is to add there chance for input to have value length=0 , so the validation won't fire any error message.
Is that possible ?
UPDATE
This is submit blocking function
<script type='text/javascript'>
$(document).ready(function() {
$('#standart_form').validationEngine();
$('#standart_form').submit(function() {
return false;
});
});
</script>
Now when I was using this 'validate[length[6,15]]'
everything was working good. But If I try using new custom functions the whole forms submits itself ruining my ajax based application.
The plugin you're using doesn't support this out of the box, but its customization features allows you to implement that behavior yourself.
For instance, you can specify a regular expression to be used when validating a field. You'll need to add it to your translation file:
"emptyOrLengthBetween6And15": {
"regex": /^$|^.{6,15}$/,
"alertText": "* Empty, or between 6 and 15 characters long"
},
Then you can refer to it in a custom
validator:
class="validate[custom[emptyOrLengthBetween6And15]]"
You can also write your own validation function:
function checkEmptyOrLengthBetween6And15(field, rules, i, options)
{
var val = field.val();
if (val.length > 0 && (val.length < 6 || val.length > 15)) {
return "* Empty, or between 6 and 15 characters long";
}
}
Then use it in a funcCall
validator:
class="validate[funcCall[checkEmptyOrLengthBetween6And15]]"
精彩评论