I have an input box where user can enter their domain. I want to make sure the domain should be like that:
example.com
hello.com
okay.com
NOT
I mean no http, https and www at the beginning of the domain.
So far I got this:
} elseif( !preg_match('/^[a-zA-Z. ] $/', $domain) ) {
$output['message'][] = 'Your domain should be start with http, https or www but can contain (.)com';
}
How can I improve this preg_match function to get the desire validation?
CodePudding user response:
Try this /^(?!(www|http|https)\.)\w (\.\w ) $/
It matches
example.com
hello.com
okay.com
example.123
1.example.com.cn
s3.amazonaws.com
It doesn't match
www.example.com
https://www.hello.com
https://okay.com
http.example.com