jQWidgets Forums
jQuery UI Widgets › Forums › Editors › MaskedInput › Custom regex
Tagged: jqwidgets mask input, masked input
This topic contains 6 replies, has 3 voices, and was last updated by cosostones 11 years, 11 months ago.
-
AuthorCustom regex Posts
-
Hello,
I would like to specifiy a custom regex to match those text :
Match : 5 numbers or first is a 2 and the second is A or B with three numbers
64445
22354
2A654
2B132Not match :
A9874
2C123
456Z5I tried to make it accordinf to this post : http://www.jqwidgets.com/community/topic/issue-with-jqxmaskedinput/#post-5346 but I couldn’t achieve it.
Regards.
Hi,
My post in the referred topic shows how to associate a Regex to a character in the Masked Input. You can learn how to create regular expressions here: http://www.w3schools.com/jsref/jsref_obj_regexp.asp and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FRegExp.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comThanks for your response,
I forgot to put the regular expression in the post, there it is : (([0-9][0-9])|(2a|2b|2A|2B))[0-9]{3}.
I tested it on this website and it works : http://www.regular-expressions.info/javascriptexample.html.
I thought understand that I need to split the regular expression and apply it on each character of the textbox put I couldn’t achieve it.
Regards.
Where is setRegex in the documentation??? I wanted to set a zipcode mask to use either the US 5 digit zip code or the US zip plus 4, and setRegex seems like it would do the trick. Is there a way to apply it to the entire input element rather than to each character?
Hi,
You may take a look at http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxmaskedinput/defaultfunctionality.htm?web. The IP masked input uses the method. With setRegex, you can associate a Regular Expression with each masked character.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comThat’s not very practical, sorry. For those of you who stumble upon this, here is how I handle validating a US zip code entry.
1. Change the jqxMaskedInput to just a jqxInput.
2. In your validator, add a custom function to capture the values and validate it (I used a regex that checks for either a 5 digit zip code or the zip plus 4):{ input: '#zipcode', message: 'A five digit zip code (11111) or five digit zip plus 4 (11111-1111) is for a zip code', action: 'keyup, blur', rule: function (input) { var zippattern = /^\d{5}([\-]?\d{4})?$/; return (zippattern.test(input.val())==true); } },
Hello,
Thanks for your solution.
Regards.
-
AuthorPosts
You must be logged in to reply to this topic.