Validation on the value entered in Single line text field

MC30
Tera Guru

Hi Experts,

Can anyone help with the below requirement ?

While entering ay value in Single line text of a catalog item. If that contains a word call "NCX" at any place then we should display an error stating NCX VM is not available.

Example: 7878ty-NCX99769 -  This should display error

Thanks in Advance.

1 ACCEPTED SOLUTION

Mahendra RC
Mega Sage

Hello MC,

Please check with below code:
You can create onSubmit or onChange Catalog client script as per your requirement. 
if you want that user should not be able to submit the form with "NCX" in that field then use onSubmit
if you want a validation when user change the field value then use the onChange catalog client script and you can show the error message.

function onSubmit() {
    var fieldValue = g_form.getValue("your_field_name");
    if (fieldValue.indexOf("NCX") >= 0) {
        g_form.showFieldMsg("your_field_name", "NCX not allowed", "error"); // if you want to show error message on field
        g_form.addErrorMessage("NCX not allowed");
        return false;
    }
}

Please mark this as helpful/correct, if it answer your question.

Thanks

View solution in original post

2 REPLIES 2

Mahendra RC
Mega Sage

Hello MC,

Please check with below code:
You can create onSubmit or onChange Catalog client script as per your requirement. 
if you want that user should not be able to submit the form with "NCX" in that field then use onSubmit
if you want a validation when user change the field value then use the onChange catalog client script and you can show the error message.

function onSubmit() {
    var fieldValue = g_form.getValue("your_field_name");
    if (fieldValue.indexOf("NCX") >= 0) {
        g_form.showFieldMsg("your_field_name", "NCX not allowed", "error"); // if you want to show error message on field
        g_form.addErrorMessage("NCX not allowed");
        return false;
    }
}

Please mark this as helpful/correct, if it answer your question.

Thanks

Hello MC,

Just wanted to check with you, if the my above response answered your question. If yes, then please do close this thread/question my marking the appropriate response as correct.

If you still need any further help or guidance on this then please update those on this question.

Thanks