a-zA-Z
matches upper and lower case letters\d
matches digits\s
matches white space:
matches a colon
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 01-21-2021 05:00 AM
Field validation: Does not contain
This is an addition to the Field validation: Regular Expressions article.
Where before we checked for a specific format and matched the pattern, this article allows us to check if the input does not contain a certain character or pattern.
A little recap
You can use regular expressions throughout the system. If you want to validate a value input in the Service Catalog for a user requesting an item you can set up a Variable Validation Regex.
For more info read Field validation: Regular Expressions article.
Negating
Negating is used if you want to check if the input does not contain a certain character or pattern.
For example:
[^a-zA-Z\d\s:]
^[^$-/:-?{-~!"^_`\[\]]*$
Result
Valid inputs:
Letters [valid]:
Letters, numbers and space [valid]:
Special character [invalid]:
Prevent repetition
If you want to allow a value (for example special characters) but not multiple times, that can be done as well by using the following:
^(?=.*[-!$%^&*()_+|~=`{}\[\]:";'<>?,.\/]*)(?!.*([-!$%^&*()_+|~=`{}\[\]:";'<>?,.\/]).*\1).*$
-
^abc$ - Starts/end with
-
<(?= - positive lookahead: Matches a group after the main expression without including it in the result.
-
.* - any character except newline 0 or more times
-
[-!$%^&*()_+|~=`{}\[\]:";'<>?,.\/] - special characters
-
* - 0 or more times
-
?! - negative lookahead: Specifies a group that can not match after the main expression (if it matches, the result is discarded).
Result
No special character [valid]:
1 or more special characters without repetition [valid]:
1 or more special characters repeated [invalid]:
Let me know if you have any additional use-cases for this and feel free to comment on any improvements! 🙂
- 3,046 Views