Java Script Task-6: On change of phone number, need to validate, it should contain only numbers and + symbol if any other characters are there then showing the error “Invalid value, please enter only numbers or +”
User Story: If you enter the phone number in phone number field then need to validate that only accept numbers and + symbols if you entered other than these show error as Invalid value, please enter only numbers or + symbol.
1) 1) Create one Phone number field in respective entity
2) Write Java Script code:
· Retrieve the phone number
· Give the null check as if phone number is not equal to null and phone number is not equal to undefined then provide the phone number format.
· If given phone number as matches to given phone number format the clear the notification
· Otherwise provide the error notification.
3) Create one web resource and add created java script code here.
4) Open Entity form Properties and add this Web Resource
· Add On change event of Phone number field
function phoneNumber(executionContext)
{
var formContext = executionContext.getFormContext();
var phone = formContext.getAttribute("effi_phonenumber").getValue();
if (phone != null && phone != undefined)
{
var format = /^\+?[0-9]{10}$/;
if (phone.match(format))
{
formContext.getControl("effi_phonenumber").clearNotification();
}
else
{
formContext.getControl("effi_phonenumber").setNotification("Invlaid Value, please enter only 10 numbers starts with +");
}
}
}
Add above code in web Resource
and give field on change event
Output:
Comments
Post a Comment