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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Validate Textarea to accept only characters no special symbols or numbers.

    Dear all,
    Greetings,
    I have been scratching my mind for couple of times to know how could i restrict a textarea to only accept character's A-Z. No special symbols like @#!| and numbers are allowed. When i give them it should be throw me an error message.

    I tried few jquery implementations. But nothing works for me as i m not aware how to apply them.

    Can some one help on how to acheive this.

    Would be great.!

    Thanks!

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,603
    Thanks
    0
    Thanked 645 Times in 635 Posts
    <textarea pattern="^[a-zA-Z]*$"> should do it in browsers that support HTML 5. To add support for that to other browsers see http://javascriptexample.net/domform12.php
    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.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    HTML5 sure is neat.
    But you still cannot trust it. That assumes that an HTML form is used and obeys the pattern. Its pretty much the same with a preg_match though.
    PHP Code:
    $p '/^[a-z]*$/i';
    if (
    preg_match($p$content))
    {
        print 
    'thats good.';

    Where $content is the string.
    You can also use ctype_alpha which is also just a-z case insensitive.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Tags for this Thread

    Posting Permissions

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