SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    prevent entry of special characters

    Hi,

    I have a form that collects customer details, I would like to prevent the user from entering special characters in the Name and address fields. I have regular expressions and a function to validate the form. At the moment, all I have is one regular expression which validates the telephone is digits. For the name and address my function only checks for empty filed but I would like to expand it.



    PHP Code:
    re1 = /^[0-9]{11,16}$/; 

    function 
    validForm(passForm){ 

    if (
    passForm.custname.value == "") { 

    alert ("Please complete the form, fields marked with * are mandatory"
            
    passForm.custnam.focus() 
            
    passForm.custnam.select() 

            return 
    false 


    if (!
    re1.test(passForm.btel.value)) { 

    alert ("Please enter a valid Phone number - this should be at least 11 digits starting with zero"
            
    passForm.btel.focus() 
            
    passForm.btel.select() 


            return 
    false 


    return 
    true 



  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ian Anderson
    www.siteguru.co.uk


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
  •