mirror of
https://github.com/a2nt/webpack-bootstrap-ui-kit.git
synced 2024-10-22 11:05:45 +02:00
FIX: field validation updates
This commit is contained in:
parent
95dbd0a6a7
commit
7d94afc8a1
@ -75,11 +75,15 @@ const FormValidateField = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// validate URL
|
// validate URL
|
||||||
if ($el.hasClass('url') && val.length && !this.valideURL(val)) {
|
if (
|
||||||
|
$el.hasClass('url') &&
|
||||||
|
unmaskedVal.length &&
|
||||||
|
!ui.valideURL(unmaskedVal)
|
||||||
|
) {
|
||||||
valid = false;
|
valid = false;
|
||||||
|
|
||||||
msg =
|
msg =
|
||||||
'URL must start with http:// or https://. For example: https://your-domain.com/';
|
'Invalid URL: URL must start with http:// or https://. For example: https://your-domain.com/bla-bla/?p1=b&p2=a#tag';
|
||||||
console.warn(`${NAME}: Wrong URL #${$el.attr('id')}`);
|
console.warn(`${NAME}: Wrong URL #${$el.attr('id')}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +114,7 @@ const FormValidateField = (($) => {
|
|||||||
// extra checks
|
// extra checks
|
||||||
if (extraChecks) {
|
if (extraChecks) {
|
||||||
extraChecks.forEach((check) => {
|
extraChecks.forEach((check) => {
|
||||||
const result = check();
|
const result = check($el);
|
||||||
valid = valid && result;
|
valid = valid && result;
|
||||||
if (!result) {
|
if (!result) {
|
||||||
console.log(check);
|
console.log(check);
|
||||||
@ -136,16 +140,15 @@ const FormValidateField = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
valideURL(str) {
|
valideURL(str) {
|
||||||
const pattern = new RegExp(
|
let url;
|
||||||
'^(https?:\\/\\/){1}' + // protocol
|
|
||||||
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|' + // domain name
|
try {
|
||||||
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
|
url = new URL(str);
|
||||||
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
|
} catch (_) {
|
||||||
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
|
return false;
|
||||||
'(\\#[-a-z\\d_]*)?$',
|
}
|
||||||
'i',
|
|
||||||
); // fragment locator
|
return url.protocol === 'http:' || url.protocol === 'https:';
|
||||||
return pattern.test(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setError(scrollTo = true, msg = null) {
|
setError(scrollTo = true, msg = null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user