Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JavaScriptQuestions javascript regex validate url

Have Programming Question? Ask it here!
 
 
 


Java Coder
javascript regex validate url
2 Answer(s)      2 years and 3 months ago
Posted in : JavaScript Questions


How to validate URL in regex Javascript


Advertisement
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:
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
php parse string for url
php parse string for url  Do i need a regex to parse a URL-type string in PHP
Advertisements
long validate
long validate  How to validate long type
URL Encoding and URL Decoding
URL Encoding and URL Decoding  What is URL Encoding and URL Decoding ?   URL encoding is the method of replacing all the spaces and other extra characters into their corresponding Hex Characters and Decoding
How to find the first 6 characters of string in regex?
How to find the first 6 characters of string in regex?  How to find the first 6 characters of string in regex. I know the Syntax... need the syntax to find the first 6 characters of string in regex using java
validate() and reset() methods
validate() and reset() methods   Describe validate() and reset() methods
reset() and Validate() method
reset() and Validate() method   How does reset() and Validate() method struts work
javascript
javascript  please tell me sir,this query not validating correctly..whats wrong in this query? <HTML> <HEAD> <TITLE>validate <Script language = JavaScript> function validate(theForm) { var why=""; why
javascript
javascript  <HTML> <HEAD> <TITLE>validate <Script language = JavaScript> function validate(theForm) { var why=""; why... = JavaScript> function validate() { var checkD= checkDropdown
javascript
javascript  passing javascript values to jsp   Hi Friend, Try the following code: form.jsp: <html> <script> function getMsg...;/script> <input type="button" onclick="getMsg();" value="Get Javascript value
url validation in struts2
url validation in struts2  Hi in strts2 urlValidation Application,the validation xml file (urlVaLidatiohatnAction-validation.xml) can not be reading,it con not show validation, can u please whre i have to put that file in which
Validate email id in jsp - JSP-Interview Questions
Validate email id in jsp  Hi Please Suggest me how to validate email id in JSP(Java Server Faces
Validate textfield in Java Swing
Validate Jtextfield in Java Swing In this section,you will learn how to validate the textfield by allowing only numbers to enter. For this purpose, we have used the keyEvent class.Using the method getKeyChar() of keyEvent class, we have
Validate Domain of an Email Id - JSP-Servlet
Validate Domain of an Email Id  How to validate the domain name in an Email id before sending a mail for an application using Mail API. ex: a@a.com in the above email id i want to validate whether a.com is present
download image using url in jsp
download image using url in jsp  how to download image using url in jsp
JavaScript validation for decimal number
JavaScript validation for decimal number Here we are going to validate... in the textbox, the javascript takes the value of textbox and check...;) } } function validate(){ var dec=document.form.num.value
Saving URL in local disk - Java Beginners
Saving URL in local disk  Hi Friend, How can i Save URL like "www.jagran.com " on local disk throgh java Statement. Thanks ,in advance
Javascript - JDBC
Javascript   Hi, I am doing a project in healthcare domain... and javascript I want to write the event handling code in another jsp page .so... want to use javascript in JSP page so that when click() event will generate
To download a website from a given url. - JSP-Servlet
To download a website from a given url.  write a program to download a website from a given URL.it must download all the pages from that website.it should take the depth of retrieval from user input.all the files pages must
PHP Variables from URL
PHP Variables from URL Are you facing problem passing PHP variable from URL... one thing if you are passing unnecessary information in the URL is fine but if you are passing confidential information like password or username in the URL
javascript for prompt - JSP-Servlet
javascript for prompt  Dear Sir, I am using a prompt() for taking... then that prompt was not coming..So please tel me how to validate a prompt() in javascript. Thanks
Validate JTexField with date on Text Changed event - Java Beginners
Validate JTexField with date on Text Changed event  Hello Sir I want to only Validate date in MM/DD/YYYY Format on TextChanged Event,date will automatically set through MM with two digits,then cursor will automatically set
javascript - XML
javascript  HI, Greetings.... I want to call javascript file i.e. ".js" from xml file. If it is possible tell me how to do that. and i want to know how to call javascript function from xml... Please help me in this regard
JavaScript basic
JavaScript basic  What does "1"+2+4 evaluate to?   Since "1" is a string, everything is a string, so the result is a string of "124
Tracking Session using URL rewriting
Tracking Session using URL rewriting In this section we will discuss about tracking user's session using URL rewriting using a simple example. For tracking sessions, we can use URL rewriting in place of cookies. Since http
JavaScript basic
JavaScript basic  How about 2+5+"8"?   Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it?s concatenation, so 78 is the result
JavaScript basic
JavaScript basic  What is === operator ?   The ==== operator is strict equality operator, it returns true only when the two operands are having the same value without any type conversion
how i do url encoding process - JSP-Servlet
how i do url encoding process  hai to all how i do the url encoding., when i passing data from one jsp page to another page,while passing some... post method., but here i want some of the url encodings plz help me., thanx
javascript - Ajax
click on particular image of slide show in javascript. i used href tag but it does not work so i m posting my javascript code here below. note: in the head
Javascript array
Javascript array  Write a javascript code to,(numerically) Enter the array size from the user Input the array elements from the user display the array elements reverses it and display   Hello Friend, Try this: <
Displaying image when clicked on URL in jsp - JSP-Servlet
Displaying image when clicked on URL in jsp  Hi, I am using struts2 in my application.. In the appliaction there is an url eg:: URL For Screenshot : abc.jpg here abc.jpg is a url and when clicked would show me an image
Javascript code
Javascript code  Dear Sir, Please help me..It s urgently required.Please help me.I have three types of electrical meters data with their testing dates saved in database with their id.Meters specifications are 11kv,33kv and >
How can I get the full URL with the attached parameters? - JSP-Servlet
How can I get the full URL with the attached parameters?  Hi, I'm trying to figure out how to get the current url and use it in my jsp page. I... parameters. For example if the url of the JSP page is: http://localhost
struts url problem in Switching module using SwitchAction class - Struts
struts url problem in Switching module using SwitchAction class  when... from my login module to admin module it shows the url of login module..., but when a jsp page come after switching ,it shows url of login module
PHP Variables in JavaScript
functionality, validate forms and  so on. JavaScript is used to give additional...PHP Variables in JavaScript JavaScript and PHP both are scripting language for the web. Moreover, JavaScript is basically  a client side scripting
javascript - JSP-Servlet
Disabled JavaScript on Browser  How can i disabled JavaScript for a particular browser
JavaScript code - Java Beginners
JavaScript code  how to write the client side validation code in javascript for a html file having field userid & password
javascript - Java Beginners
Javascript enable button  I need a code of JavaScript enable button that changes the event on click
Boolean functions in JavaScript
Boolean functions in JavaScript  Explain about the Boolean functions present in Javascript
array_pop javascript
array_pop javascript  array_pop JavaScript and in PHP
Uses of javascript, ActiveX in XML
Uses of javascript, ActiveX in XML  hi.. Can I use JavaScript, ActiveX, etc in XML files? please anyone tell me Thanks
javascript - Java Beginners
javascript  javascript is said to be as a serverside scriting language but when the web program is written using javascript the program is executed even when internet is switched off. How this is happening
maximize an image using javaScript
maximize an image using javaScript  Write the code to maximize an image using javaScript
javascript in firefox - Java Beginners
javascript in firefox  i am not able to run javascript in firfox. firefox does not run javascript. i have also enabled it from tool -> options and checked on enabled javascript still its does not run. it does give any
javascript - Java Beginners
javascript  hi, tell me hoe to create saveAs dialog box in javascript.  Hi, The following link contains code for saveAs dialog Box. I think it will helpful for u. http://4umi.com/web/javascript/filewrite.php
JavaScript Defer Attribute
JavaScript Defer Attribute  defer attribute in javascript   Hi Friend, The defer attribute gives a hint to the browser that the script does not create any content so the browser can optionally defer interpreting
javascript string - Java Beginners
javascript string  what is the differenece between ' and " in javascript.   Hi!Friend. here is your answer............. The only advantage I have seen in using ' to build strings is that I can do stuff
javascript - Java Beginners
javascript   hi sir, i have two items in drop down list box that is (one is employee and another one is self employee) if i select employee, one text box has to be create in javascript. how to do it pls tell me
 

 

 

DMCA.com