Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

regex validate field

Not applicable

I am using onSubmit client script to validate the three (dev_endpoint, prod_endpoint and test end point) field values with regex.  But not sure its not working well. 

 

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var devUrl = g_form.getValue('development_endpoint');
    var testUrl = g_form.getValue('test_endpoint');
    var prodUrl = g_form.getValue('production_endpoint');
    var validationRegexURL = /^https:\/\/[\w\-]+(\.[\w\-]+)+[\/#?]?.*$/;
    var validationRegexURI = /^(?!.*\.(js|html|css|jpg|jpeg|gif|png|ico|pdf|doc|docx|xls|xlsx|ppt|pptx|csv|txt|xml|json)$)(?!.*\b(get|put|delete)\b)[a-z][a-z0-9_-]*(?:_[a-z0-9]+)*(?:\/[a-z][a-z0-9_-]*(?:_[a-z0-9]+)*)*(?:\/[a-z][a-z0-9_-]*(?:_[a-z0-9]+)*)*(?!.*[\/]$)$/;
    if (!validationRegexURL.test(devUrl)) {
        g_form.showFieldMsg('development_endpoint', 'Invalid URL. Please enter a valid HTTPS URL, starting with https:// and containing a valid domain name, followed by an optional path, query parameters, or fragment identifier.', Error);
        return false;
    }
    if (!validationRegexURL.test(testUrl)) {
               g_form.showFieldMsg('development_endpoint', 'Invalid URL.', Error);
        return false;
    }
    if (!validationRegexURL.test(prodUrl)) {
        g_form.showFieldMsg('test_endpoint', 'Invalid URL', Error);
        return false;
    }
    if (!validationRegexURI.test(prodUrl)) {
        g_form.showFieldMsg('production_endpoint', 'Invalid URL. Please enter a valid HTTPS URL', Error);
        return false;
    }
    return true;
}
2 REPLIES 2

H S B
Giga Guru

Can you please share sample URL for all 3 environments which are valid & non-valid?

 

Looking at the script doesn't make much sense about the requirement.

Not applicable

User has provided these two regex to validate the text : 

^https:\/\/[\w\-]+(\.[\w\-]+)+[\/#?]?.*$/;

 

^(?!.*\.(js|html|css|jpg|jpeg|gif|png|ico|pdf|doc|docx|xls|xlsx|ppt|pptx|csv|txt|xml|json)$)(?!.*\b(get|put|delete)\b)[a-z][a-z0-9_-]*(?:_[a-z0-9]+)*(?:\/[a-z][a-z0-9_-]*(?:_[a-z0-9]+)*)*(?:\/[a-z][a-z0-9_-]*(?:_[a-z0-9]+)*)*(?!.*[\/]$)$