Comments (6)
I just realize that the match validation rule can be used for exactly that purpose.
from jquery-validator.
I tried to make a custom validation for a time (hh:mm) value. The match:/^([01]\d|2[0-3]):?([0-5]\d)$/ string should do the trick. However, it contains the alternation regex character (pipe symbol) that can't be used in the match validation rules because it is already used for separating the validation rules. When I try to use the above rule it is split at the | character and javascript crashes due to an unmatched parenthesis. Is there any solution for this?
from jquery-validator.
Also, it is not possible to use a colon (the : character) in the regular expression because it is already used for separating the rule name from a given value.
from jquery-validator.
I think I'll probably add custom validation rules so that you don't have to rely on the match/regex rule.
$(document).ready(function() {
$('#myForm').validator({
events : 'submit',
selector : 'input[type!=submit], select, textarea',
callback : function( elem, valid ) {
if ( ! valid ) {
$( elem ).addClass('error');
}
},
validate_time: function(attribute, value, parameters) {
return /^([01]\d|2[0-3]):?([0-5]\d)$/.match(value);
}
});
});
And of course, the markup:
<input type="text" data-validations="time">
What do you think about that?
from jquery-validator.
That would be great. But what about the Laravel validation rules? I suppose the server and client side validation should match as much as possible. Can I make suggestions for the Laravel validation rules too?
from jquery-validator.
I'm not sure what you mean. You're obviously not going to be able to completely reuse code - this plugin isn't going to execute arbitrary PHP - but you could reuse your regular expression.
For example:
Validator::register('awesome', function($attribute, $value, $parameters)
{
return $value == Config::get('validation.awesome');
});
And in your template (using Blade):
$('...').validator({
...
validate_awesome: function (attribute, value, parameters) {
return value == {{ Config::get('validation.awesome') }};
}
});
Obviously, that's just a string comparison, but it would be easy to modify for regular expressions.
Anyway, I added the custom validation rules, so you should be able to do things like I mentioned in the comment above.
from jquery-validator.
Related Issues (20)
- Validation fails for radio buttons. HOT 4
- Validation fails after second submit when new validation rules are added. HOT 2
- The size validation rule does not work for non numeric attributes. HOT 3
- Negative numbers are always validated as invalid.
- Length validation fails to flag max length has been exceeded when textarea contains linefeeds.
- Validation crashes when using [] brackets in name of input element.
- Validation crashes for mutiple select. HOT 4
- Validation fails when input element has no 'name' attribute.
- The jquery-validator.js plugin fails JSLint (The JavaScript Code Quality Tool from Douglas Crockford). HOT 1
- Laravel 4 package HOT 2
- ReadMe.md missing "!" HOT 1
- A way to know which validation failed? HOT 2
- Can't install in laravel 4 HOT 1
- laravel 4 HOT 1
- Can you update this to Laravel 4? HOT 3
- validate_accepted() ignores checked status on checkboxes HOT 1
- it didn't have packagist json code HOT 1
- where is the error message displayed HOT 2
- The size attribute with file input type doesn't seem to be working HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jquery-validator.