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
Post a Comment