Skip navigation
Currently Being Moderated

How can I validate "Name" spry-textfields???

Jun 26, 2012 7:39 AM

Tags: #cs5.5 #dreamweaver #javascript #spry #dreamweaver_cs5 #ajax #textfield #validation #regular_expressions

Hi I would like some information, if its possible.

 

I'm building a contact form and I want to add some validation to the fields using Spry.

 

The problem comes for my First Name and Last Name spry-textfields, where from the properties panel in type menu there is not any proper format like e-mail or zip-code has. The only thing I found that might help me is the custom option, but dont know exactlly how to use it. Basicly I 'd like to add some regular expressions to check that these fields will accept only characters and whitespaces, no numbers or symbols like @,#, etc etc

 

Is there any article or video (better) available that can help me work with that??

 

Any help would be appreciated.

 
Replies
  • Currently Being Moderated
    Jun 26, 2012 8:10 AM   in reply to Lykos22

    <!doctype html>

    <html>

    <head>

    <meta charset="utf-8">

    <title>Untitled Document</title>

    <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet">

    </head>

     

    <body>

    <span id="sprytextfield1">

      <label for="text1"></label>

      <input type="text" name="text1" id="text1">

      <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span>

    </span>

     

    <script src="SpryAssets/SpryValidationTextField.js"></script>

    <script>

    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "custom", {validation:myValidation, validateOn:["blur", "change"]});

    function myValidation(value) {

      return /^[a-zA-Z\s.\-]+$/.test(value)

    }

    </script>

    </body>

    </html>

    Gramps

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 26, 2012 9:28 AM   in reply to Lykos22

    <!doctype html>

    <html>

    <head>

    <meta charset="utf-8">

    <title>Untitled Document</title>

    <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet">

    </head>

     

    <body>

    <span id="sprytextfield1">

      <label for="text1"></label>

      <input type="text" name="text1" id="text1">

      <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span>

    </span>

     

    <script src="SpryAssets/SpryValidationTextField.js"></script>

    <script>

    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "custom", {validation:myValidation, validateOn:["blur", "change"]});

    function myValidation(value) {

      return /^[a-zA-Z\s.\-]+$/.test(value)

    }

    </script>

    </body>

    </html>

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 26, 2012 5:26 PM   in reply to Lykos22

    What is the problem? What is it that doesn't work?

     

    For regular expressions you might like to go to http://regexlib.com/

     

    Gramps

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 27, 2012 7:43 PM   in reply to Lykos22

    I have looked all over the place to help you, but could not find a solution. Maybe you could try adding the letters of the Greek alphabet in a similar manner as a-zA-Z.

     

    Gramps

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points