Dynadot โ€” .com Transfer

How do I make a form to require certain strings of text?

Spaceship Spaceship
Watch
Impact
32
Here is the basic input field that I want to change:
PHP:
<input type=text maxlength='40' name=ProductName size=31>
I want to make it so people can only enter domain names into that field. So I need either one of the following; .com, .net, .org, etc, etc. to be required in that field. So if someone types in "holiday units" it will come up with an error message stating that the domain name is not formated properly (or something like that).
How do I do this?
Many thanks for helping out.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
You need a JavaScript verification in the submit handler.
 
0
•••
Look into using regular expressions as well. You can do the verification on your action page just in case javascript is disabled.
 
0
•••
In theory, the best way to do it is to use both.

PHP REGEX to find .com, .net, etc.
Code:
$domain = "blah.com";
$exts = array(".com",".net");
foreach ($exts as $ext) {
if(preg_match("/$ext/",$domain) {
flag = 1;
}
}
if($flag) {
//.COM or .NET exist
}
else {
//Not a domain
}
 
0
•••
Change formname to the name of your form. (If you don't have one, add one and put it into this code.)
Code:
<script type="text/javascript">
function check() {
	var str = document.formname.ProductName.value;
	var reg = new RegExp("[^ ]*(\.)[a-zA-Z0-9-]{2,6}");
	if (reg.test(str))
	{
		document.formname.submit();
	}
	else
	{
		alert(str + " is not a valid name");
		return false;
	}
}
</script>




Add the following inside of your <form ...> tag and your <input type="submit" ....> tag
Code:
onsubmit="check();"
 
0
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back