Regex Text Field Validator for iPhone
I have the following behavior of a desktop version of a software:
- a text field is validated with a regex
abc|xyz
- this means that a user is allowed to type
a
,ab
,x
,xy
,abc
,xyz
, other symbols will not be shown in a text field
I have to port such behavior to iphone.
Strings a
, ab
, x
, xy
does not match to regex abc|xyz
that's why matching user input will restrict typing any char to a text filed. Is there any way to match a user input as a beginning of a regex string? Ini开发者_Go百科tial regex should not be modified (^$ could be added).
The desktop version uses QRegExpValidator class from Qt. QRegExpValidator has Intermediate state that is a
, ab
, x
, xy
in my case. It uses matchedLength() to determine Intermediate state
Also I had a look through NSRegularExpression and RegexKitLite
Have a look at PCRE - Perl Compatible Regular Expressions. It is rumored to be used in Apple products.
精彩评论