alphanumeric

Returns a regular expression for validating email addresses that only accepts lowercase letters and digits, corresponding to the following pattern: ^[0-9a-z]+@[0-9a-z]+\.[0-9a-z]+$.


Pattern symbols

Here's the explanation associated to each symbol used in this pattern:

  • ^ Beginning. Matches the beginning of the string, or the beginning of a line if the multiline flag (m) is enabled.

  • [] Character set. Match any character in the set.

  • 0-9 Range. Matches a character in the range "0" to "9" (char code 48 to 57). Case-sensitive.

  • a-z Range. Matches a character in the range "a" to "z" (char code 97 to 122). Case-sensitive.

  • + Quantifier. Match 1 or more of the preceding token.

  • @ Character. Match a "@" character (char code 64).

  • \. Escaped character. Matches a "." character (char code 46).

  • $ End. Matches the end of the string, or the end of a line if the multiline flag (m) is enabled.


Calling from Kotlin

Here's an example of calling this function from Kotlin code:

val regex: EmailAddressRegex = EmailAddressRegex.alphanumeric()
val expected = """^[0-9a-z]+@[0-9a-z]+\.[0-9a-z]+$"""
assertEquals(expected, "$regex")

Calling from Java

Here's an example of calling this function from Java code:

final EmailAddressRegex regex = EmailAddressRegex.alphanumeric();
final String pattern = regex.toString();
final String expected = "^[0-9a-z]+@[0-9a-z]+\\.[0-9a-z]+$";
Assertions.assertEquals(expected, pattern);