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

Discussion in 'PHP' started by JasMate, Jan 31, 2007.

  1. #1
    Here is the basic input field that I want to change:
    <input type=text maxlength='40' name=ProductName size=31>
    PHP:
    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.
     
    JasMate, Jan 31, 2007 IP
  2. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #2
    You can use regular expressions for this check, like this:

    
    $s = trim(@$_POST['ProductName']);
    if (preg_match('/^[a-z0-9-]+\.((com)|(org)|(net))$/si',$s))
     echo "OK";
    else
     echo "Information is not valid";
    
    PHP:
     
    wmtips, Feb 1, 2007 IP
  3. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Additionally, if the address seems to be valid, you could also check whether the domain is or isn't registred. That can be done with lots of free WHOIS PHP scripts (just googeled, and by example cwhois at www.vibralogix[dot]com /cwhois/index.htm is such a script/function).
     
    DeViAnThans3, Feb 1, 2007 IP