javascript regex validate url

javascript regex validate url

How to validate URL in regex Javascript

View Answers

May 11, 2012 at 10:53 AM

<html>
<head>
<title>Url validation using regex</title>
<script type="text/javascript">
    function validate() {
        var url = document.getElementById("url").value;
        var pattern = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
        if (pattern.test(url)) {
            alert("Url is valid");
            return true;
        } 
            alert("Url is not valid!");
            return false;

    }
</script>

</head>
<body>
<h2>Validating Url..</h2>
Url :
<input type="text" name="url" id="url" />
<input type="submit" value="Check" onclick="validate();" />
</body>
</html>

May 12, 2012 at 1:22 PM

url pattern is like HYPERLINK

"http://www.roseindia.net/hibernate/examples/criteria"

http://www.roseindia.net/hibernate/examples/criteria


In pattern = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!-\/]))?/;

/../(forward slashes) is used to quote your regular expression.

() is used to group the content.

| is used for or condition

\/ backslash consider / as a literal .

\w+ for one or more alphanumeric value.

{0,1} shows the range of content having length between 0 to 1.

* matches the preceding character zero or more time.

[..] matches any letter enclosed with in.

+ shows that preceding character come 1 or more times.

. Shows that \ will treat . as a literal.

$ is used for ending the string.

test() method takes one argument and check that to the pattern.









Related Tutorials/Questions & Answers:
javascript regex validate url
javascript regex validate url  How to validate URL in regex Javascript   <html> <head> <title>Url validation using regex</title> <script type="text/javascript"> function validate
JavaScript regex validate validate Zip.
JavaScript regex validate validate Zip.  JavaScript regex validate - how to validate Zip?   <html> <head> <title>Zip Code validation using regex</title> <script type="text/javascript">
Advertisements
JavaScript regex validate Telephone no.
JavaScript regex validate Telephone no.  JavaScript regex validate... validation using regex</title> <script type="text/javascript"> function validate() { var phone = document.getElementById("phone").value
JavaScript regex validate Mobile no.
JavaScript regex validate Mobile no.  JavaScript regex validate... validation using regex</title> <script type="text/javascript"> function validate() { var mobile = document.getElementById("mobile").value
JavaScript regex validate Character
JavaScript regex validate Character  JavaScript regex validate... using regex</title> <script type="text/javascript"> function validate() { var name = document.getElementById("name").value; var
JavaScript regex validate Character
JavaScript regex validate Character  JavaScript regex validate... using regex</title> <script type="text/javascript"> function validate() { var name = document.getElementById("name").value; var
javascript regex validate currency
javascript regex validate currency  How to validate currency in JavaScript?   <html> <head> <title>Currency validation using regex</title> <script type="text/javascript"> function
javascript regex validate Special character
javascript regex validate Special character   javascript regex validate Special character   <html> <head> <title>Zip Code validation using regex</title> <script type="text/javascript">
javascript regex validation alphanumeric
javascript regex validation alphanumeric  How to write javascript regex validation for alphanumeric?   <html> <head> <.../javascript"> function validate() { var name = document.getElementById
javascript regex validation email
javascript regex validation email  How to write JavaScript regex... validation using regex</title> <script type="text/javascript"> function validate() { var email = document.getElementById("email").value
ModuleNotFoundError: No module named 'url-regex'
ModuleNotFoundError: No module named 'url-regex'  Hi, My Python... 'url-regex' How to remove the ModuleNotFoundError: No module named 'url... have to install padas library. You can install url-regex python with following
URL validation in JavaScript
URL validation in JavaScript In this tutorial we are going to discuss, how to validate a URL in JavaScript. Java Script is a Scripting language. A Java... into the html page. Using Java Script we are going to validate a URL, entered
JavaScript regex exec() method for text match.
JavaScript regex exec() method for text match.  JavaScript regex exec...; regex exec() for text matching</title> <script type="text/javascript"> function validate() { var name = document.getElementById("name
javascript date validation using regex
javascript date validation using regex  Hi, I want to validate the date using javascript. Please help.   <html> <head> <title>Validating Date format</title> <script type="text/javascript">
validate radio button using javascript
validate radio button using javascript  validate radio button using javascript
JavaScript Validate UK Date
JavaScript Validate UK Date  How to Validate UK Date in JavaScript   <SCRIPT> function validateDate(dtControl) { var input = document.getElementById(dtControl) var validformat=/^\d{1,2}\/\d
javascript for websites url validation
javascript for websites url validation  javascript for websites url validation   JavaScript Code for URL Validation **function isvalidurl(url) { return url.match(/^(ht|f)tps?:\/\/[a-z0-9-.]+.[a-z]{2,4}\/?([^\s<
validate select tag items in javascript
validate select tag items in javascript  Hi, How to validate addition of two numbers from two different <select> tag items in JavaScript..? Thanks in advance
RegEx
RegEx  I want to know the javascript RegEx code for validation of ( ) parenthesis.. The code is validating the parenthesis but after submit the parenthesis is disappear. what should i do
url capture in javaScript
url capture in javaScript  Hi All, I m creating a bookmark to capture the url of the site and the user's input in the bookmark,in javaScript.this url and user input is to be saved into DB. Following is my code.Result
JavaScript Open URL
JavaScript Open URL...; In this section, you will learn how to open the url on the window.  As we know that window.location object that contains the current URL information
JavaScript Navigate to URL
JavaScript Navigate to URL...; JavaScript provides several methods and properties which allow the user... to the specified URL "http://www.roseindia.net". Here is the code:ADS
how to validate the telephone number without using jquery in html with javascript
how to validate the telephone number without using jquery in html with javascript  how to validate the telephone number without using jquery in html with javascript
How do i validate form using javascript and send data to database?
How do i validate form using javascript and send data to database?  I need a "JOIN US" form that can validate using javascript and be able to connect....") return false; } } return true } function validate(){ var
Calling In JavaScript Functions from HTML Form To Validate User Entered Data
Calling In JavaScript Functions from HTML Form To Validate User Entered... and editing my html to call my functions to validate the user entered data...;title>Subscription Form</title> <script type="text/javascript">
JavaScript validate select tag
JavaScript validate select tag In this tutorial, you will learn how to validate html select tag. Here, we have used two select tags to select numbers...; <script language = "Javascript"> function validate
How to Validate dynamically created text box in HTML using Javascript
How to Validate dynamically created text box in HTML using Javascript  Here is the HTML code to create text boxes dynamically. It works properly.... And also how to validate the text boxes created dynamically. <html>
Validate
Validate   hi all..im a beginner java and i need some help from u guys.. Its about validate. My HR request BF = 'brought forward', leave cannot apply date greater than 31/03 of particular year. So, if the user apply the date
JAVASCRIPT
JAVASCRIPT  I have one textbox and I want to validate that it must start with number(1-0). can anyone tell me a javascript for that ? thanks in advance
Java REGEX
Java REGEX  I have a String {"name":"ashish","surname":"singh"} I have to check whether each word is surrounded by the " (double quotes) or not using the java regex. without using Json lib. Kindly help
replacing regex in large files
replacing regex in large files  replacing regex in large files
JQuery url validation
jQuery url Validation : jQuery "required url" is the method to validate or check url if the element is empty (text input) or  wrong url type entered .We can validate our url in another type by writing the "url
Javascript
" method="post" onsubmit="javascript:return validate();"> Phone Number:<... this format xxx-xxx-xxxx, i want the code in javascript. as a function.   Javascript Phone Number Validation <html> <script> function
JavaScript location.replace() method
JavaScript location.replace() method       JavaScript method location.replace(URL) immediately redirects to the specified URL location. After calling replace() method ,you cannot go
ModuleNotFoundError: No module named 'regex'
ModuleNotFoundError: No module named 'regex'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'regex' How to remove the ModuleNotFoundError: No module named 'regex'
Version of com.belteshazzar>regex dependency
List of Version of com.belteshazzar>regex dependency
Version of com.techshroom>Regex dependency
List of Version of com.techshroom>Regex dependency
Validate <select> tag Items
Validate select tag Items  Hi, How to validate addition of two numbers of two different "select" tag items in JavaScript..? Thanks in advance
Validate <select> tag Items
Validate select tag Items  Hi, How to validate addition of two numbers of two different "select" tag items in JavaScript..? Thanks in advance
JavaScript
JavaScript  clone JavaScript
javascript
javascript  please tell me sir,this query not validating correctly..whats wrong in this query? <HTML> <HEAD> <TITLE>validate <Script language = JavaScript>ADS_TO_REPLACE_1 function validate(theForm
javascript
javascript  <HTML> <HEAD> <TITLE>validate <Script language = JavaScript> function validate(theForm) {ADS_TO_REPLACE_1 var...; function validate() { var checkD= checkDropdown(document.f1.choose.selectedIndex
JavaScript - JavaScript Tutorial
JavaScript Tutorials is one of the best Quick reference to the JavaScript. In this JavaScript reference you will find most of the things about java script. JavaScript tutorial is classified into sections with examples. This tutorial
JavaScript - JavaScript Tutorial
JavaScript Tutorials is one of the best Quick reference to the JavaScript. In this JavaScript reference you will find most of the things about java script. JavaScript tutorial is classified into sections with examples. This tutorial
javascript
javascript  javascript code to dynamically add table on button click.../javascript/javascriptexamples/javascript-add-row-dynamically.shtml http://www.roseindia.net/javascript/javascript-add-row-to-table.shtml http://www.roseindia.net
Javascript
Javascript  How validations are done using javascript ,with example? and interview questions on javASCRIPT
Javascript Form validation Example
Javascript Form validation Example In this section we will discuss about how to validate your application form in javascript. In many applications data... inserted is correct or not you will be required to validate your form. Here I
php parse string for url
php parse string for url  Do i need a regex to parse a URL-type string in PHP
JavaScript
should use JavaScript? Thanks   Hi, JavaScript is scripting language that runs on browser. You have to embed JavaScript in HTML page. Please see JavaScript tutorial. Thanks
JavaScript
JavaScript  how to get full path of a file type in javascript

Ads