SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Apr 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow Restricting "@, www, http, com, edu, org" from a textarea

    Hi all,

    I have a text box and I want to prevent users from entering a website, an email address, or a phone number.

    I was thinking I would need to restrict http, www, @, (at), (###), ###-, .com, .edu, .org, .info, .us.

    How do I go about doing this? (The more details the better, I'm a nub.)
    Thanks so much!

  2. #2
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any particular reason why you would want to do this with Javascript and on input? People could just turn off Javascript and then write it in anyway, and correct me if I'm wrong but spambots don't even have Javascript.
    Dan G
    Marketing Strategist & Consultant

  3. #3
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,751
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First off, welcome to the forums and don't forget to introduce yourself in the Introduction Forums.

    With regards to your issue, there is in inherit issue with using javascript for any kind of validation, which is that people can simply disable it, circumventing any sort of validation protection you have set in place. My recommendation would be to do this in your server side language (PHP I will assume), and redirect them back to the form page indicating that there was an error with there text, and to remove any of the above.

    However, I am concerned as to what your validation hopes to accomplish. A phone number can be done a number of ways:

    1-800-000-0000
    1.800.000.0000
    18000000000
    +39 945 3949
    etc.
    What's to tell from them entering a regular number? That said, maybe go into some detail as to what you're looking at doing that requires this sort of restriction.

  4. #4
    SitePoint Member
    Join Date
    Apr 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by c2uk View Post
    Any particular reason why you would want to do this with Javascript and on input? People could just turn off Javascript and then write it in anyway, and correct me if I'm wrong but spambots don't even have Javascript.
    Well, we have a captcha in place to prevent spambots. As for people turning off Javascript, that is definitely a possibility. If people do enter their phone number/email address in the textbox, however, it is not the end of the world. If this prevents 95% of people from entering their phone number or email address, I would be happy with that.

  5. #5
    SitePoint Member
    Join Date
    Apr 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I'm halfway there. A guy with the alias MMJ helped me out. Anyway, I can now disable a string of characters. I have javascript in place that validates the form so I was able to set the validation to false if a certain character string was detected. Here's the relevant code if anyone's interested:

    else if(document.[theformsname].[categoryname].value.match('http'))
    {
    alert("Please do not include websites, email address or phone numbers.");
    document.[theformsname].[categoryname].focus();
    return false;
    }

    Anyway, I now need to figure out how to disable a string of numbers, (###) or ###- for example. Any help would be great appreciated!

  6. #6
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't want to come off track, but you're sure that your captcha prevents the spambots? Various captchas have been broken recently, including Yahoo's and Google's

    So, if you haven't already I'd advise you to look into a server side solution for preventing email/websites/etc as well, and not just rely on javascript.

    For a Javascript solution, you could try regular expression check: http://www.javascriptkit.com/javatutors/redev.shtml
    Dan G
    Marketing Strategist & Consultant

  7. #7
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Gugel View Post
    I think I'm halfway there. A guy with the alias MMJ helped me out. Anyway, I can now disable a string of characters. I have javascript in place that validates the form so I was able to set the validation to false if a certain character string was detected. Here's the relevant code if anyone's interested:

    else if(document.[theformsname].[categoryname].value.match('http'))
    {
    alert("Please do not include websites, email address or phone numbers.");
    document.[theformsname].[categoryname].focus();
    return false;
    }

    Anyway, I now need to figure out how to disable a string of numbers, (###) or ###- for example. Any help would be great appreciated!
    Yeah, thats me.

    Since any input value is text just use the same function with the string of your desire.

    Also, since most bots don't compile javascript this will not be effective against them. You have to do some checking on the server-side.

  8. #8
    SitePoint Member
    Join Date
    Apr 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by M-M-J View Post
    Yeah, thats me.

    Since any input value is text just use the same function with the string of your desire.

    Also, since most bots don't compile javascript this will not be effective against them. You have to do some checking on the server-side.
    Is there a more efficient way to do this other than ('000'), ('001'), ('002'), ('003')...? That would take forever and generate like a 1MB file

  9. #9
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you check out regular expressions, they are there for just to solve this kind of problem, though I don't have the time to come up with one for Javascript (and test it) that works for your use case.
    Dan G
    Marketing Strategist & Consultant

  10. #10
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Gugel View Post
    Is there a more efficient way to do this other than ('000'), ('001'), ('002'), ('003')...? That would take forever and generate like a 1MB file
    Why are you looking for certain numbers?

    You can just do variable.match(/111|222|333|444/)

    Seperate each match with |


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •