Speed up development with full-stack environments for every branch.

Learn More

JSVerbalExpressions Example - check for valid url

Forked from How to use the jQuery $().ready function.

18 Runs 95 Views 12 Copies
Saved

Saved

gtsolutions 373

gtsolutions
published 4 years ago

<html>
    <head>
        <meta charset="utf-8">
        <title>JSVerbalExpressions Example - check for valid url</title>
        <script type="text/javascript" src="js/VerbalExpressions.js"></script>
    </head>

    <body>
        <script>
            // Create an example of how to test for correctly formed URLs
            var tester = VerEx()
            .startOfLine()
            .then( "http" )
            .maybe( "s" )
            .then( "://" )
            .maybe( "www." )
            .anythingBut( " " )
            .endOfLine();

            // Use RegExp object's native test() function
            var test1 = "https://www.google.com"
            if( tester.test( test1 ) ) alert( '"' + test1 + '" is a correct URL!'); 
            else alert( '"' + test1 + '" is a incorrect URL!'); 
            
            var test2 = "ht//an invalid url";
            if( tester.test( test2 ) ) alert( '"' + test2 + '" is a correct URL!'); 
            else alert( '"' + test2 + '" is an incorrect URL!'); 
        </script>
    </body>
</html>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).