- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 01:26 PM
Hi Community,
I am currently using a regular expression of .{1,30} to limit the characters to 30 on a field. I want to add to it so no spaces (beginning, middle or end) are allowed and no special characters are allowed. Can anybody help with this? Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 06:34 AM
Hi @chrish5,
This should be better 🙂
^([A-z]|[0-9]){1,30}$
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 07:49 AM
Yup, works correctly trying it from the Catalog Item, but not the Service Portal. Thanks for your help Peter.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 07:18 AM
Hello @chrish5,
To limit the characters to 30 on a field, and also exclude spaces and special characters, you can use the following regular expression:
^[a-zA-Z0-9]{1,30}$
This regular expression means:
- ^: The start of the string or line
- [a-zA-Z0-9]: A character class that matches any alphanumeric character (upper or lower case letters or digits)
- {1,30}: A quantifier that specifies the minimum and maximum number of repetitions of the previous element (in this case, the character class)
- $: The end of the string or line
This regular expression will only match strings or lines that consist of 1 to 30 alphanumeric characters, and nothing else. It will not allow any spaces or special characters, such as punctuation marks, symbols, or whitespace characters.
You can test this regular expression online using a tool like RegExr or Regex101.
Hope this helps.
Kind Regards,
Swarnadeep Nandy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 07:25 AM
Hi @SwarnadeepNandy,
That is actually exactly the same, only more complicated looking by splitting up [A-z] to [azA-Z] 🙂
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 07:28 AM
Essentially Yes. Just Different ways of writing.
