javascript method to check a valid URL [duplicate] - javascript

This question already has answers here:
What is the best regular expression to check if a string is a valid URL?
(62 answers)
Closed 9 years ago.
I there any JavaScript way (regex) or module to check if a string is a URL which the follows following schema http://en.wikipedia.org/wiki/URI_scheme.
NOTE -
I have seen other questions related to this in stackoverflow and none of them are satisfactory.
Most of them are the regex which matches the http/https/ftp URL but what about feed or mailto URL or URL with any other schema as specified in http://en.wikipedia.org/wiki/URI_scheme

The following regex does what you are requesting.
It validates a string if it holds a URL as specified in RFC 3986.
Both absolute and relative URLs are supported.
^([a-z][a-z0-9+\-.]*:(//([a-z0-9\-._~%!$&'()*+,;=]+#)?([a-z0-9\-._~%]+|\[[a-f0-9:.]+\]|\[v[a-f0-9][a-z0-9\-._~%!$&'()*+,;=:]+\])(:[0-9]+)?(/[a-z0-9\-._~%!$&'()*+,;=:#]+)*/?|(/?[a-z0-9\-._~%!$&'()*+,;=:#]+(/[a-z0-9\-._~%!$&'()*+,;=:#]+)*/?)?)| ([a-z0-9\-._~%!$&'()*+,;=#]+(/[a-z0-9\-._~%!$&'()*+,;=:#]+)*/?|(/[a-z0-9\-._~%!$&'()*+,;=:#]+)+/?))(\?[a-z0-9\-._~%!$&'()*+,;=:#/?]*)?(\#[a-z0-9\-._~%!$&'()*+,;=:#/?]*)?$
I did not come up with this regex, it is created by JGSoft

Related

Regular expression for EDU emails with sub domains [duplicate]

This question already has answers here:
How can I validate an email address using a regular expression?
(79 answers)
Closed 2 years ago.
I am attempting to create a regular expression for validating edu emails which may or may not have a sub domain. Some schools have emails like "example#hms.harvard.edu" while other schools have emails like "example#stanford.edu".
([0-9]|[a-z]|[A-Z])+#([0-9]|[a-z]|[A-Z])+([0-9]|[a-z]|[A-Z])\.edu$"
This is the current regular expression that I have but I am not well versed in these.
I am looking to create an expression that will validate emails with one domain and emails with a subdomain.
Any help would be appreciated. Thanks!
In most cases, /^[-\w.]+#[-\w.]+\.edu$/ should be enough.
The only problem with this solution would be, that it can also accept domains like hms..harvard.edu.
To prevent this, you could use this regex instead: /^[-\w.]+#([-\w]+\.)*[-\w]+\.edu$/
Edit: use \w instead of [0-9a-zA-Z_]
This should do the trick (modified from http://emailregex.com/ - referenced in How to validate an email address using a regular expression?):
/^(([^<>()\[\]\\.,;:\s#"]+(\.[^<>()\[\]\\.,;:\s#"]+)*)|(".+"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+edu))$/

How to pass a string which contain UTF-8 characters from javascript to PHP? [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
How to store other languages (unicode) in cookies and get it back again
(1 answer)
Closed 5 years ago.
I'm building a references generator and I need to keep track of the generated references. To achieve this, I'm currently using Javascript to store a cookie containing the raw data, then a PHP page embedded on the result page takes the cookie and logs it into an HTML page, however, some characters appears like this : �. I really don't know which way to go to solve this (base64 encoding, unicode encoded characters...)
Here's the link to the website : http://louisfelixberthiaume.000webhostapp.com/source_siteweb.php
[It's in french]
I can't give you the link to the HTML page for obvious confidentiality reasons, however I'll provide a screenshot :
Generated references screenshot

Difference between toLocaleLowerCase() and toLowerCase()? [duplicate]

This question already has answers here:
In what JS engines, specifically, are toLowerCase & toUpperCase locale-sensitive?
(2 answers)
Closed 7 years ago.
What is the difference between these two ?
The description for the toLocaleLowerCase() mentions Converts a string to lowercase letters, according to the host's locale.
What is the host's locale ?
Definition and Usage as per w3schools
The toLocaleLowerCase() method converts a string to lowercase letters, according to the host's current locale.
The locale is based on the language settings of the browser.
Generally, this method returns the same result as the toLowerCase() method. However, for some locales, where language conflict with the regular Unicode case mappings occurs (such as Turkish), the results may vary.

email address validation in JavaScript using regular expression [duplicate]

This question already has answers here:
How can I validate an email address in JavaScript?
(79 answers)
Closed 7 years ago.
I'm currently trying to validate email address using regular expression in JavaScript. These are the requirements of the Email address:
The email field contains a user name part follows by "#" and a domain name part.
The user name contains word characters including hyphen ("-") and period (".").
The domain name contains two to four parts of alphabet characters word extension.
Each word extension is separated by a period (".") and the last extension must have two to three characters.
Among four requirements, the third one is most confusing to me. I will be very appreciate if someone can help me. Thank you.
I have tried the first answer in this page, but this answer accept even 5 or more extensions, so it doesn't meet my third requirement.
For Javascript, here is the regex you need which follows the RFC 5322 standard:
/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*#([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i
Side note: it is better to use a very weak regex (basically just matching the '#') and sending a confirmation email.

Regex for valid URL (Javascript) (with a twist) [duplicate]

This question already has answers here:
Javascript regex to find a base URL
(2 answers)
Closed 6 years ago.
a simple regext that can test
Either but atleast one of (http, https, or www).
I've seen examples that has compulsion of protocol, or allows directly like google.com.
but for users, they are used to typing www., not all would type the protocol.
But still it should be a valid one, and not a "abced.com"
https://regex101.com/#javascript
there use (option1|option2|option3)
If you just need to test if the url starts with http, https, www then you can simply use /^(https?|www)/.
If you need a full regex for the url then check out Mathias Bynens post on the matter https://mathiasbynens.be/demo/url-regex and pick the one most suited to your needs.

Categories

Resources