Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patterns #31

Closed
MimisK13 opened this issue Apr 11, 2017 · 4 comments
Closed

Patterns #31

MimisK13 opened this issue Apr 11, 2017 · 4 comments

Comments

@MimisK13
Copy link

Is it possible for a pattern to be made specifically for letters and numbers, without accepting any other characters-symbol??

@SinuheM
Copy link

SinuheM commented Apr 13, 2017

I was trying this
<input type="text" pattern="letter">

And add some lines in default settings (line 38)
letter : ^[A-Za-z ]+$/i,

also near to the line 133
case 'letter' :
regex = this.settings.regex.letter
break;

@MimisK13
Copy link
Author

Thank you very much!!!

@tiomno
Copy link

tiomno commented Apr 18, 2017

You shouldn't need to modify the source to make something like this work.

The documentation explains that the correct way to do this is to add the customised regular expression to the pattern attribute like this:

<input type="text" pattern="^[A-Za-z ]+$"> Cannot include backslash (/) characters as this will be evaluated as a string and not a pattern in line 143 of validator.js

I personally would like to have the option for adding new RegExp to the settings instead of filling the HTML with crafty regular expressions. ;)

I'll PR a change for this and hope @yairEO accepts it. :)

BTW, fantastic job @yairEO, thanks a lot!

@yairEO
Copy link
Owner

yairEO commented May 30, 2017

Thank you @tiomno :)

You can already bypass the default patterns with a custom settings object.

These are the default settings:

{
    regex : {
        url          : /^(https?:\/\/)?([\w\d\-_]+\.+[A-Za-z]{2,})+\/?/,
        phone        : /^\+?([0-9]|[-|' '])+$/i,
        numeric      : /^[0-9]+$/i,
        alphanumeric : /^[a-zA-Z0-9]+$/i,
        email        : {
            illegalChars : /[\(\)\<\>\,\;\:\\\/\"\[\]]/,
            filter       : /^.+@.+\..{2,6}$/ // exmaple email "steve@s-i.photo"
        }
    },
    alerts  : true,
    classes : {
        item  : 'field',
        alert : 'alert',
        bad   : 'bad'
    }
}

And you can pass it when you instantiate a validator object:

var settings = { 
    regex : { 
        phone : [...]
    } 
};
var validator = new FormValidator({}, settings)

(The first argument is an Object with the texts you wish to override)

@yairEO yairEO closed this as completed May 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants