6. On change of phone number, need to validate, it should contain only numbers and + symbol if any other characters are there then show the error “Invalid value, please enter only numbers or +”

 

User Story: On change of phone number, need to validate, it should contain only numbers and + symbol if any other characters are there then show the error “Invalid value, please enter only numbers or +”

1. Write a JavaScript function to validate a mobile number using regular expression and place it in web resource

2. Write a regular expression for mobile number format        

        ·         Check mobile number contains numbers and + symbol 

                 §  If no set a field error notification "Invalid value, please enter only numbers or +"

                 §  Else clear field error notification

2. Call JavaScript function from phone number field on change

Write a JavaScript function to validate a mobile number using regular expression and place it in web resource

function phonenumber(executionContext)

{

    var formContext = executionContext.getFormContext();

    var phone = formContext.getAttribute("crb67_phoneno").getValue();

    if (phone != null && phone != undefined)

    {

        var expression = /^\+91[ ]?[6-9]([0-9]{9})$/;

 

        if (expression.test(phone)) {

          //  return true;

            formContext.getControl("crb67_phoneno").clearNotification();

        }

        else {

            formContext.getControl("crb67_phoneno").setNotification("Please enter valid phonenumber");

            //alert("Please enter valid phonenumber including + ");

           // return false;

        }

    }

   

 }   Call JavaScript function from phone number field on change





Out put:










Comments

Popular posts from this blog

2. On Click of case Reject button, show popup with reject reason text, once filled and submitted, reject reason field should get filled and case should be in read only

1. In Case Entity, based on Incident Type selection, filter the case category using the category-incident master entity

8. On selection of asset in case entity, read the project in asset, project start date and end date from project entity, set the dates on case entity from as project start date and end dates