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 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.