21
Views
5
Comments
Solved
Input Regex Set Error Message/Text?
Service Studio Version
11.54.74 (Build 63545)

I just realized we can use the attributes in the input widget to set the regex pattern for the input. 
However, how do I set the error message that was being occurred? 

In this request name I set regex such that it can only accept alphabets ("^[A-Za-z]+$")

For instance, without input, the error message will display "This field is required". 

If there is an invalid input such as special characters or numbers the error message will display, "Enter a valid text."

This is the configuration for the input widget. 


Is there a way to override the "Enter a valid text." to, " Can only be in alphabets"? 

I have tried using the set ValidMessage on client action, however, it will render both (Empty input & Wrong input) with the same error message that is set. 


Attached is my OML File for reference.

NewRegexDemo.oml
2023-01-27 13-47-30
Ahmad Aqil
Solution

Hi Chin Kai,

If you want to override that message you can simply change it here, but its not the best solution because if you have multiple input that have different regex pattern, so every field will have different message.

The best way is to make it custom validation , when you save that form..you need to validate the input using Regex_Search with your regex pattern.

Please find attached oml file for your reference.

Thanks,

Regards,

Aqil

NewRegexDemo_Updated.oml
UserImage.jpg
Chin Kai

Hi Aqil, Thank you so much! 

{but its not the best solution because if you have multiple input that have different regex pattern}

okay I understand what you mean because this set up is for the entire project, so whichever screen that has this input will be affected or receive the same "Error Message" 

I saw the regex, Great Work! Thanks!


2023-01-27 13-47-30
Ahmad Aqil

Yes exacty! no problem..happy coding!

2023-01-27 13-47-30
Ahmad Aqil
Solution

As an additional suggestion, I would recommend using an input mask to prevent the user from keying in anything other than alphabets. This way, there's no need to click the save button and validate... but it all depends on your requirements. 

There are some input mask component in the Forge, this is one of it, so you can explore this:

Input Mask Reactive 

Thanks,

Regards,

Aqil

UserImage.jpg
Chin Kai

Thanks for suggesting another alternative solution, will look into that as well. Cheers!

2023-01-27 13-47-30
Ahmad Aqil
Solution

Hi Chin Kai,

If you want to override that message you can simply change it here, but its not the best solution because if you have multiple input that have different regex pattern, so every field will have different message.

The best way is to make it custom validation , when you save that form..you need to validate the input using Regex_Search with your regex pattern.

Please find attached oml file for your reference.

Thanks,

Regards,

Aqil

NewRegexDemo_Updated.oml
UserImage.jpg
Chin Kai

Hi Aqil, Thank you so much! 

{but its not the best solution because if you have multiple input that have different regex pattern}

okay I understand what you mean because this set up is for the entire project, so whichever screen that has this input will be affected or receive the same "Error Message" 

I saw the regex, Great Work! Thanks!


2023-01-27 13-47-30
Ahmad Aqil

Yes exacty! no problem..happy coding!

2023-01-27 13-47-30
Ahmad Aqil
Solution

As an additional suggestion, I would recommend using an input mask to prevent the user from keying in anything other than alphabets. This way, there's no need to click the save button and validate... but it all depends on your requirements. 

There are some input mask component in the Forge, this is one of it, so you can explore this:

Input Mask Reactive 

Thanks,

Regards,

Aqil

UserImage.jpg
Chin Kai

Thanks for suggesting another alternative solution, will look into that as well. Cheers!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.