Comments (5)
No, since I'm piggy-backing off of HTML5 validation, there won't be any official support for textarea regex validation, but you can add a custom function validator that will run your regex like this:
#20 (comment)
In the next release, I'll probably add support into the API for custom validator functions, but this should solve your problem in the mean time.
from bootstrap-validator.
thanks for help. Now regex validation on textarea working like charm
js:
Validator.VALIDATORS.pattern = function ($el) {
var patternRegExp = $el.data('pattern');
return $el.val().match(eval(patternRegExp));
}
html:
<textarea class="form-control" cols="20" data-error="error" data-pattern="/regex_here/g" data-pattern-error="error_text" name="name" placeholder="place_text" required="required" rows="5"></textarea>
from bootstrap-validator.
i'm beginner with bootstrap, need more help on this for textarea validation.
from bootstrap-validator.
@aryac what you can do is to edit the source of the plugin and add the error text for pattern matching:
Validator.DEFAULTS = {
delay: 500,
html: false,
disable: true,
custom: {},
errors: {
match: 'Does not match',
minlength: 'Not long enough',
pattern: 'Illegal characters'
}
}
and then add the method (prefer new regExp()
in Validator.VALIDATORS
:
Validator.VALIDATORS = {
'native': function ($el) {
var el = $el[0]
return el.checkValidity ? el.checkValidity() : true
},
'match': function ($el) {
var target = $el.data('match')
return !$el.val() || $el.val() === $(target).val()
},
'minlength': function ($el) {
var minlength = $el.data('minlength')
return !$el.val() || $el.val().length >= minlength
},
'pattern': function ($el) {
var pattern = $el.data('pattern')
return !$el.val() || new RegExp(pattern,"g").test($el.val())
}
}
Then in you <textarea>
add
data-pattern="your regex"
This works but it is not an encouragement to do user input filtering/sanitizing in the frontend.
from bootstrap-validator.
You don't need to edit the source code of the plugin* since custom validators are now supported via the API. Pass the validator and error in as options when you initialize the validator.
$('#myForm').validator({
custom: {
pattern: function ($el) {
var pattern = $el.data('pattern')
return !$el.val() || new RegExp(pattern,"g").test($el.val())
}
},
errors: {
pattern: "Illegal characters"
}
})
*Even before custom validators were fully supported, the preferred way to accomplish what you're suggesting would have been to add the extra validator and error at runtime inside of your own script instead of modifying the source of the plugin directly, since doing so would make future upgrades harder.
$.fn.validator.Constructor.VALIDATORS.pattern = function (e) {...}
$.fn.validator.Constructor.DEFAULTS.errors.pattern = "..."
from bootstrap-validator.
Related Issues (20)
- How to show the list of errors?
- Cannot activate from Javascript
- Needs to Bootstrap 4 Support Validation HOT 1
- Validator to compare two daterange fields issues in comarision
- Bootstrap validator HOT 1
- Session is still present until i dont refresh the page
- Trigger change on text not work
- little issue with customized style for error message
- Form wonβt submit after validation triggers HOT 1
- Custom validation doen't add has-error class on Select2 HOT 1
- valida on click one field
- Get input value in error messages (Custom Validation) HOT 1
- change language for error message in spanish
- THIS PROJECT SEEMS TO BE ABANDONED HOT 1
- Hi if i want to make more custom validation how can i do it? Like.. HOT 2
- Error during Minification
- How to format before validation
- Make Custom Validator Global
- validate on click issue
- Custom validator doesn't validate on jquery 3.0 - 3.4 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 bootstrap-validator.