validating a url using Regex in javascript [duplicate] - javascript

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Validate email address in Javascript?
What is the best regular expression to check if a string is a valid URL?
I want to test that whether the string is url or not, right now I am stuck at this point.
I am using this regex to validate my URL
/(https|http):\/\/([_a-z\d\-]+(\.[_a-z\d\-]+)+)(([_a-z\d\-\\\.\/]+[_a-z\d\-\\\/])+)*/;
The problem with this regex is that it fails to validate this type of URL
http://www.abc/abc/
how to check that case.?

Related

regex to check 2 IP address [duplicate]

This question already has answers here:
Reference - What does this regex mean?
(1 answer)
Reuse capturing group pattern in JS regex
(3 answers)
Closed 3 years ago.
I have a requirement in which I have a range of 2 IP addresses.
192.168.1.1-192.168.1.1
I want to check that whether both side of dash are valid IP addresses. For single IP address I have a regex but I am not able to add a '-' for checking 2.
Need some help. Below is single IP regex.
^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$

Regex to take only domain specific email [duplicate]

This question already has answers here:
How to match all email addresses at a specific domain using regex?
(5 answers)
Closed 7 years ago.
I have written one regex to take only email domain as yahoo.com.
"^[a-zA-Z0-9]+#yahoo\.com$"
but when i enter amit.sahay#yahoo.com, it says invalid email id.
Please help.
Thanks.
You didn't added .(dot) within your character class over here so your updated regex would be
^[a-zA-Z0-9.]+#yahoo\.com$
//^^ added (.dot) over here

Regex to validate against URL [duplicate]

This question already has answers here:
What is the best regular expression to check if a string is a valid URL?
(62 answers)
Closed 8 years ago.
We have regex to validate URL. I need a regex that will validate against it. Kindly help me in this.
URL for proper validation
var regexp = /(ftp|http|https)://(\w+:{0,1}\w*#)?(\S+)(:[0-9]+)?(/|/([\w#!:.?+=&%#!-/]))?/
What's for validating against, i.e it should not be a URL.
Just negate the regex using negative lookahead,
^(?!^((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+#)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+#)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%#.\w_]*)#?(?:[\w]*))?)$).*$
DEMO

What's the best regex to validate names? [duplicate]

This question already has answers here:
Regular expression for first and last name
(28 answers)
Regex for names
(27 answers)
Closed 8 years ago.
I'm creating a web store and I need to validate inputs with JavaScripts so the user doesn't have to submit a form to be given the PHP errors (although I'm also validating the form with PHP).
What I came up with is the following regex:
/^[a-zA-Z]+$/
But the above regex would only allow alpha characters whereas I also want to allow characters such as ' and - since obviously names may also contain these two characters. My question is, how to make a regex to allow alpha characaters AND the two characters above.
Besides that I also have one more question which just came in my mind, characters such as ă will pass the above validation ?
By adding them to your character group like so
/^[a-zA-Z'-]+$/

Email validation using javascript [duplicate]

This question already has answers here:
How can I validate an email address using a regular expression?
(79 answers)
Closed 9 years ago.
I am using
/^[a-zA-Z0-9\-_]+(\.[a-zA-Z0-9\-_]+)*#[a-z0-9]+(\-[a-z0-9]+)*(\.[a-z0-9]+(\-[a-z0-9]+)*)*\.[a-z]{2,4}$/
to validate my email IDs , but it has some issues like it is allowing below type mail ID which are invalid.
EX:
1. 1234#1234.com
2. 12deepak#abc.com
3. _deepak#abc.com
I have tried a lot by modifying the regular expression but not succeeded.
Any one please suggest me a correct regular expression ?
Try using
/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))#((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i
Source: jQuery validation plugin

Categories

Resources