java - Get specific message on regex validation -
is possible specific message on regex validation?
for eg.
our regex '[0-9]{1,5}'
, user enters '123456'
message 'max characters exceeded'
, if user enters 'abcd'
message 'invalid characters'
should displayed.
does have idea??
thanks in advance.
there no "automatic" solution. can hold several regular expressions , seek match input against these regexes holding error message per regex. example:
pattern correctinput = pattern.compile("\\d{1,5}"); pattern onlydigits = pattern.compile("^\\d*$"); if (!correctinput.matcher(input).find()) { homecoming onlydigits.matcher(input).find()) ? "wrong number of characters" : "invalid characters"; }
java android regex
No comments:
Post a Comment