Required Regex for mobile number validation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2020 10:51 AM
Hi Team,
i need regex for validating mobile number. Its simple that we need to validate 1 variable when user gives his mobile number it should start with country code (example : +91,+46). If not it should show an alert that your number is not valid as its missing with country code.
I have checked in previous community questions but for country code validation i am not able to find. Need assistance.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2020 12:58 PM
As your script is running on change so it cannot stop from saving the record. You need to make your variable mandatory as
Also, instead of clearing the variable on an invalid number, you can instead display a field message[recommended] or alert to just inform the end-user about the invalid format. That would be a better UX.
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2020 01:24 PM
To prevent invalid values from being submitted, it's better to define a "Variable Validation Regex" rather than try to validate in a client script.
Steps:
- Open "Service Catalog" > "Catalog Variables" > "Variable Validation Regex" from Application Navigator
- Select "New"
- Enter regular expression for mobile phone number
- Open Catalog Item with mobile phone number field
- Open Variable for mobile phone number
- In "Type Specification" table, select the regex for mobile phone number defined above
Now, a field message will appear if the mobile number is in incorrect format.
Selecting "Order Now" will also show an error in the form and prevent the form from being submitted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2020 03:02 PM
I have done the same steps using different regex rules, but for some reason the validation message from the Question Regular Expression only shows if I use the 'Try Now' in the catalog Item form.
If I try to run it through service portal, I see the space open below the field where the message should be and if I inspect that area using the browser, I see that my text is there, but it is formatted as white text on a transparent background...
Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2020 01:48 PM