How can I check an attribute length using data validation function using regex?

Question

In the Function Builder of the Validation Functions, how can I set a length check for email where the characters before '@' sign cannot exceed 20 characters?

Below is what I currently have for overall email validation, which works fine, but now I need to add the above length check of 20 characters on the username portion (before the '@' sign).

^[_a-zA-Z0-9%-]+([.][_a-zA-Z0-9%-]+)*[@]((fmc-ag.com|fmc-asia.com|fmc-na.com|fresenius.co.jp|freseniusmedicalcare.com))$

 

Answer

The solution to the regex definition is:

 

^[a-zA-Z0-9.]{1,20}[@]((fmc-ag.com|fmc-asia.com|fmc-na.com|fresenius.co.jp|freseniusmedicalcare.com))$

 

 Additional information
 

1. Checking for a Specific Length Range

If you want to ensure a string is between a certain minimum and maximum length using regex, you can construct a regex pattern like this:

  • For a string of length exactly 5 characters:
    regexCopy code /^.{5}$/ 
    • ^ asserts the start of the string.
    • .{5} matches any character (except newline) exactly 5 times.
    • $ asserts the end of the string.
  • For a string of length between 3 and 6 characters:
    regexCopy code /^.{3,6}$/ 
    • ^ asserts the start of the string.
    • .{3,6} matches any character (except newline) between 3 and 6 times.
    • $ asserts the end of the string.

 

2. Checking for Minimum or Maximum Length

If you only need to check for a minimum or maximum length:

  • For a string of at least 4 characters:
    regexCopy code /^.{4,}$/ 
    • ^ asserts the start of the string.
    • .{4,} matches any character (except newline) at least 4 times.
    • $ asserts the end of the string.
  • For a string of at most 10 characters:
    regexCopy code /^.{0,10}$/ 
    • ^ asserts the start of the string.
    • .{0,10} matches any character (except newline) between 0 and 10 times.
    • $ asserts the end of the string.

 

Was this article helpful?
0 out of 0 found this helpful

Comments

1 comment
  • Why cant I see the whole content?

    0

Please sign in to leave a comment.