Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

add site url validation regex

const regex = /^((ftp|http|https)://)?(www.)?(?!.*(ftp|http|https|www.))[a-zA-Z0-9_-]+(.[a-zA-Z]+)+((/)[w#]+)*(/w+?[a-zA-Z0-9_]+=w+(&[a-zA-Z0-9_]+=w+)*)?$/gm;
const str = `http://www.sample.com
https://www.sample.com
http://www.sample.com/xyz
www.sample.com
www.sample.com/xyz/#/xyz
sample.com
www.sample.com
mofiz.com
kolim.com
www.murikhao.www.sample.com
http://murihao.www.sample.com
http://www.sample.com/xyz?abc=dkd&p=q&c=2
www.sample.gov.bd
www.sample.com.en
www.sample.vu


`;
let m;

while ((m = regex.exec(str)) !== null) {

    if (m.index === regex.lastIndex) {
        regex.lastIndex++;
    }
    console.log("matched :"+m[0]);
}
Comment

regex valid url

/^(?:(?:https?|ftp)://)(?:S+(?::S*)?@)?(?:(?!(?:10|127)(?:.d{1,3}){3})(?!(?:169.254|192.168)(?:.d{1,3}){2})(?!172.(?:1[6-9]|2d|3[0-1])(?:.d{1,3}){2})(?:[1-9]d?|1dd|2[01]d|22[0-3])(?:.(?:1?d{1,2}|2[0-4]d|25[0-5])){2}(?:.(?:[1-9]d?|1dd|2[0-4]d|25[0-4]))|(?:(?:[a-zu00a1-uffff0-9]-*)*[a-zu00a1-uffff0-9]+)(?:.(?:[a-zu00a1-uffff0-9]-*)*[a-zu00a1-uffff0-9]+)*(?:.(?:[a-zu00a1-uffff]{2,})).?)(?::d{2,5})?(?:[/?#]S*)?$/i
Comment

regex for url validation js

/((?:(?:http?|ftp)[s]*://)?[a-z0-9-%/&=?.]+.[a-z]{2,4}/?([^s<>#%",{}|^[]`]+)?)/gi
Comment

Validate URL With Regex

$regex = "((https?|ftp)://)?";
$regex .= "([a-z0-9+!*(),;?&=$_.-]+(:[a-z0-9+!*(),;?&=$_.-]+)?@)?";
$regex .= "([a-z0-9-.]*).([a-z]{2,3})";
$regex .= "(:[0-9]{2,5})?";
$regex .= "(/([a-z0-9+$_-].?)+)*/?";
$regex .= "(?[a-z+&$_.-][a-z0-9;:@&%=+/$_.-]*)?";
$regex .= "(#[a-z_.-][a-z0-9+$_.-]*)?";

$url = 'https://mydomain.com/';

if (preg_match("/^$regex$/i", $url)) {
   echo('Enter URL is a valid URL');
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native cover image 
Javascript :: self executing async function in js 
Javascript :: javascript settimeout 
Javascript :: google dinosaur game 
Javascript :: get site url javascript 
Javascript :: counter cdn 
Javascript :: hide header react navigation 
Javascript :: ajax get request 
Javascript :: javascript run every 5 seconds 
Javascript :: javascript check if undefined 
Javascript :: check if localstorage key exists 
Javascript :: jquery is checkbox checked 
Javascript :: how to get last path from url in javascript 
Javascript :: how to remove dash from string in javascript 
Javascript :: node console log without newline 
Javascript :: emmet not working react js 
Javascript :: javascript remove line breaks from string 
Javascript :: how to know connected internet in js 
Javascript :: js show span for 5 seconds 
Javascript :: how to install robotjs 
Javascript :: pick a random element from an array javascript 
Javascript :: jquery disable class attribute 
Javascript :: js random number between 1 and 100 
Javascript :: javascript check if blank space 
Javascript :: javascript select element with attribute 
Javascript :: how to trigger change of summernote 
Javascript :: javascript close window after print 
Javascript :: update to specific version of node brew 
Javascript :: node express server static files 
Javascript :: react bootstrap colors not working 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =