Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jan 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to validate text area with out any phonenumber,name,emailid,urls

    hi,

    i want to validate textarea,so that user canot enter words like phone number, email address or any url .how i can stop the user from entering these words using javascript.

    thanks
    thulasiram

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I don't know why you posted this in the PHP forum when you've specifically asked for javascript.
    Moving to javascript forum.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,729
    Thanks
    202
    Thanked 2,507 Times in 2,485 Posts
    Quote Originally Posted by Fou-Lu View Post
    I don't know why you posted this in the PHP forum when you've specifically asked for javascript.
    Moving to javascript forum.
    Too vague. Can the user enter a number which is not a telephone number? 76 trombones?

    Do you simply want to delete for example @ signs and www and http? Or erase the entire phrase/sentence??

    It is not easy (in fact pretty well impossible) to prevent people entering unwanted words as they can use spaces or asterisks to break the validation, and spell out the @ sign as "at". All you can do is prevent the email addresses and urls from being copied and pasted.


    This may move you forward:-

    Code:
    <textarea id = "txta1" rows = "20" cols = "50" onkeyup = "validate()"></textarea>
    
    <script type = "text/javascript">
    function validate() {
    var txt = document.getElementById("txta1").value;
    txt = txt.replace(/www/gi,"");
    txt = txt.replace(/http/gi,"");
    txt = txt.replace(/@/gi,"");
    txt = txt.replace(/([0-9])(\s+)([0-9])/gi,"$1$3");  // remove spaces between numbers
    txt = txt.replace(/\d{6,}/,"");  // 5 digits max in sequence
    document.getElementById("txta1").value = txt;
    }
    
    </script>
    JavaScript form validation only provides convenience for users, not security. If for example a script verifies that the user agreed to a firm's terms of service, or filters invalid characters out of fields that should only contain numbers, or calculates the cost of purchases, the validation must also be performed server-side, and not just on the client.
    Last edited by Philip M; 01-02-2014 at 07:04 PM. Reason: Revised

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,454
    Thanks
    0
    Thanked 632 Times in 622 Posts
    What do you have for the server side validation of the field? It is usually easiest to copy that into the JavaScript.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    the pattern attrib now works on textrareas in most browsers:
    Code:
    <textarea pattern="^[\d\-.() ]+$"></textarea>
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #6
    New Coder
    Join Date
    Oct 2013
    Posts
    16
    Thanks
    2
    Thanked 1 Time in 1 Post

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,729
    Thanks
    202
    Thanked 2,507 Times in 2,485 Posts
    Quote Originally Posted by rnd me View Post
    the pattern attrib now works on textrareas in most browsers:
    Code:
    <textarea pattern="^[\d\-.() ]+$"></textarea>
    No, HTML5 textarea element does not support the pattern attribute.
    The pattern attribute works with the following input types: text, search, url, tel, email, and password. But in any case it is not supported by IE9 or earlier, or Safari.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #8
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by Philip M View Post
    No, HTML5 textarea element does not support the pattern attribute.
    The pattern attribute works with the following input types: text, search, url, tel, email, and password. But in any case it is not supported by IE9 or earlier, or Safari.
    you're right, and i should have read the question closer. i don't know where i thought i saw textarea's getting pattern, but that's not the case.

    technically, all <input> elements can be validated using the pattern attribute, color, number, range, etc. you could validate a color to be of a certain shade or minimum brightness, or a range/number value to be even for example...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5


  •  

    Posting Permissions

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