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 11 of 11
  1. #1
    New Coder
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Checking for invalid characters excluding white space...

    hi all, i have a text box for users to enter their name....so i'm using javascript to check whether they are entering any invalid characters....is there any way to check for invalid characters excluding white space? becoz some names have a space in between....

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,062
    Thanks
    4
    Thanked 8 Times in 8 Posts
    function validateMe(field) {
    var valid = "\' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    // ALL OTHER CHARACTERS ARE INVALID
    var ok = "yes";
    var temp;
    for (var i=0; i<field.value.length; i++) {
    temp = "" + field.value.substring(i, i+1);
    if (valid.indexOf(temp) == "-1") ok = "no";
    }
    if (ok == "no") {
    alert("Invalid entry!");
    field.focus();
    field.select();
    }
    }
    Last edited by miranda; 04-04-2003 at 10:31 AM.

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeċ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    So, pure English alphabet, yes? How about &uuml;, &ouml;, &aring;, &aelig;, &ccedil; for instance?
    Code:
    // Function will return true if legal, false if not.
    // It will also return false unless the string contains at least one character.
    function fnCheckString(str){
        var re=/^[- a-z.']+$/i;
        return re.test(str);
    }
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by liorean
    var re=/^[- a-z.']+$/i;
    Is that right? Do you get start/end of line markers in text-box string returns?
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeċ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Do I have to direct YOU to my regex tutorial, too, Brothercake? I thought you would know them well enough

    You know, ^ matches start of string, not start of line. Same is the case with $, but for ends.

    Of course, if you use the m flag, they match start and end of lines, also.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by liorean
    You know, ^ matches start of string, not start of line. Same is the case with $, but for ends.
    [creeps off in embarrassment ...]
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #7
    New Coder
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for the codes!

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Heheh... and with all my "lording over" (as beetle says (how's my memory beetle? )) of regex's you haven't mastered them yet, brothercake?

    Shame shame!

    Honestly though, I have no idea what I would do without regex's, considering the type of stuff we have to validate at work sometimes. I'd probably go insane (/me points miranda to regex tutorials, especially after looking at the code above! regex's would apparently save you a bit of time too!). A couple of other good tutorials/introductions:

    http://www.siteexperts.com/tips/func...ts23/page1.asp

    http://developer.netscape.com/docs/m...ide/regexp.htm
    Last edited by whammy; 04-06-2003 at 12:16 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #9
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There's also the word boundary flag as well...
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #10
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeċ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    The DevEdge Ref and Guide are pretty good resources, but I just can't keep from linking my own article about this:

    Original: Regular Expressions in JavaScript on eVolt.
    WA Edition: Programmer's Guide to Regular Expressions on JavaScript Kit.


    Whammy - Well, the word boundary flag wasn't in discussion, even.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #11
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm all for anyone and everyone learning about regular expressions, but from looking at your articles, they assume a certain amount of technical proficiency, which most of the posters here do not have.

    They look fine to me though...
    Last edited by whammy; 04-06-2003 at 01:28 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

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