function onChange(control, oldValue, newValue, isLoading) { if (isLoading || newValue == '') { return; } g_form.hideErrorBox('url'); var pattern =/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#()?&//=]*)/ // regex pattern if(!pattern.test(newValue)){ g_form.showErrorBox('url', getMessage('Please provide Valid URL'));//show error messege g_form.setValue('url', ''); } }
Example:
https://www.workingcode.in/question/regex-validation-only-alphanumeric-with-space-allowed-servicenow/ http://www.workingcode.in/ http://11.21.123.12
Regex should allow only http(s) Protocol
Working Code Edited question July 24, 2023