Regex for domain name only [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm asking my users to write their domain name.
I'm looking for inputs of these types (=good):
http://www.Domain.com
http://Domain.com
https://www.Domain.com
https://Domain.com
www.Domain.com
Domain.com
http://no.matter.how.many.Domain.com
https://no.matter.how.many.Domain.com
no.matter.how.many.Domain.com
http://www.Domain.com/
https://www.Domain.com/
http://no.matter.how.many.Domain.com/
https://no.matter.how.many.Domain.com/
www.Domain.com/
Domain.com/
I'm want to reject any input that not in this format.
Bad inputs, for example:
http://www.Domain.com/page
http://www.Domain.com/page.html
http://www.Domain.com/page/page2
and so on...
Can you help me with a suitable RegEx?
Thank you!

You can use this regex
^(https?://)?[^/]+/?$
^depicts the start of string
$ depicts the end of string
? matches preceding group or char optionally..

Solution:
(https?://)?(www.)?([A-Za-z]+\.){1,}([A-Za-z]{2,})/?

Related

Javascript Regex replace string between 2 strings [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to figure out the best way to replace a string between 2 other strings. I believe regex is necessary for this.
Input string:
"http://domainabc.com/dir1/dir2"
Output string:
"http://domainxyz.com/dir1/dir2"
Only the domain will change - not the subdirectories.
Probably you're looking to change current domain name without bothering what the domain is. Try this code:
var s = "http://domainabc.com/dir1/dir2";
repl = s.replace(/\b(https?:\/\/)[^/]+(.+)$/, "$1domainxyz.com$2");
//=> http://domainxyz.com/dir1/dir2

Javascript zip code , six numberic digit excluding space [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have this original code. Can I know what is the meaning of this code? I confuse a bit.
if (/^\d{5}(-\d{4})?$/.test(zip.value)) {
I need to rewrite to zip code with 6 numeric digit excluding space. How should I do?
you can find your explanation here: http://rick.measham.id.au/paste/explain.pl?regex=%2F%5E%5Cd%7B5%7D%28-%5Cd%7B4%7D%29%3F%24%2F

Javascript regular expression to validate Facebook URL's [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want a regular expression in javascript that can validate all the patterns of Facebook URL's.
I have tried some of the regular expressions but i am not satisfied with those regular expression's completely.
Also i want in regular expression is that,it should take/accept the facebook url's without:
http,https or www.
Means it should accept:
facebook.com/....
www.facebook.com/...
http://facebook.com/....
https://facebook.com/...
Please suggest me the regular expression that can validate all of the URL patterns of Facebook in javascript.
Thanks
Hacked this very quick and it seems to cover your cases:
(?:(?:http|https):\/\/)?(?:www.)?facebook.com\/?
I think this should be good enough
/^(https?:\/\/){0,1}(www\.){0,1}facebook\.com/

how to escape special and non-english characters on key press? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i want to ignore all special character but "-" and non-english characters on key press in jquery. Actually this input is used to check domain availability. like;
www.________.com | for and end extensions are already provided for user. they won't enter those parts.
can you help?
You should use a onChange event, since users can also paste something into the field.
To check if the string is a valid url, use this pattern
var urlPattern = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,#?^=%&:\/~+#-]*[\w#?^=%&\/~+#-])?/

Javascript regexp replace sub-word [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to use JavaScript regexp replace text below:
i love #HTC & #HTC-One
to
i love #HTC & HTC-One
var result = "i love #HTC & #HTC-One".replace(
/#([\w-]+)/g,
'#$1');
The regex looks for words that start with # alpha numeric and -.
The word without the # is enclosed in parenthesis to make it a capturing group.
The capturing group is referenced in the replacement with $1

Categories