In my application I am adding edittext based on response provided by server. For each edittext server also provides regex pattern to match. I am able to successfully able to match pattern and do validations. But I want to identify type of regex pattern so that I can open keyboard according to value edittext should accept.
For example, If edittext should accept email address then keyboard with @ sign opens up and if edittext accept numeric values it should open numeric keypad.
Is there any library which can return type from its regex pattern such as "Email", "Number" etc. from regular expressions as there can be several different types of regex pattern?
EDIT: I know how to set input type for edittext but I need to find out type from regex pattern. I am not able to make changes in server I have to handle this on client side.
There are also two types of regular expressions: the "Basic" regular expression, and the "extended" regular expression.
A regular expression is a pattern that the regular expression engine attempts to match in input text. A pattern consists of one or more character literals, operators, or constructs.
$ means "Match the end of the string" (the position after the last character in the string).
A regex (regular expression) consists of a sequence of sub-expressions. In this example, [0-9] and + . The [...] , known as character class (or bracket list), encloses a list of characters. It matches any SINGLE character in the list.
There most probably isn't one. The reason is - there is no way to tell for sure. Anything you can come up with will be heuristic.
\d
, or number ranges ([1-5]
), or single numbers (7
) plus repetition meta characters (?
, *
, +
, {4, 12}
), it's a number validation.\w
and no @ sign, it's a regular text.Continue in the same spirit.
Use a list of strings, which you know the type of and try to match them with the regex. Aka, for emails try [email protected]
.
Use a library that can generate example strings from regex and match them with your own regexes to determine the type. Here is one for Java and another one for JavaScript.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With