Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression in Java for validating username

I'm trying the username chains in Java with following rules:

  • Length >=3
  • Valid characters: a-z, A-Z, 0-9, points, dashes and underscores.

Could someone help me with the regular expression?

like image 243
Addev Avatar asked Jul 21 '11 20:07

Addev


People also ask

How do you validate a regular expression?

You can use regular expressions to match and validate the text that users enter in cfinput and cftextinput tags. Ordinary characters are combined with special characters to define the match pattern. The validation succeeds only if the user input matches the pattern.

Is regex input validation?

The Validation (Regex) property helps you define a set of validation options for a given field. In general, this field property is used to perform validation checks (format, length, etc.) on the value that the user enters in a field. If the user enters a value that does not pass these checks, it will throw an error.


1 Answers

try this regular expression:

^[a-zA-Z0-9._-]{3,}$
like image 144
sarkiroka Avatar answered Oct 07 '22 23:10

sarkiroka