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 Coder
    Join Date
    Feb 2004
    Location
    Sweden
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation form validation + illegal characters script help

    Hi, how is it possible to make a function that allow only letter (both upper- n' lowercase) and "." (dot) and "-". In other words, how do i define characters that will pass a form validation (to be inputted into a textfield). In this validation script ->


    function guestbooksubmit(form) {
    missinginfo = "";
    if (document.guestbook.from_name.value == "") {
    missinginfo += "\n Name";

    }
    else return true;
    }


    so how can i put that fuction (only letters, . , -) into this??
    (note: that this is not the whole script)

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    you probably want to try regexp... I am not great on it, so this might help you http://www.devguru.com/Technologies/...ef/regexp.html or someone will hopefully post some code for you here...

    basically you wanna compare the string to values in the regexp.. if they dont match, then throw an error.. if they do, then submit the form....

    sorry couldnt be more help at the mo!

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    Ume, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Code:
    function guestbooksubmit(form) {
        missinginfo = "";
        if (!/^[a-z. -]+$/gi.test(document.guestbook.from_name.value)){
            missinginfo += "\n  Name";
        }
        else
            return true;
    }
    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


  •  

    Posting Permissions

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