Tuesday, 21 October 2014

URL validation using regular expression for javascript & PHP

Pattern for javascript & PHP


/^((http|https):\/\/)?(www[.])?([a-zA-Z0-9]|-)+([.][a-zA-Z0-9(-|\/|=|?)?]+)+$/


Validation function in Javascript

function checkForValidURL(value) {

    var urlregex = new RegExp("^((http|https):\/\/)?(www[.])?([a-zA-Z0-9]|-)+([.][a-zA-Z0-9(-|\/|=|?)?]+)+$");
    if (urlregex.test(value)) {
        return (true);
    }
    return (false);
}

0 comments:

Post a Comment