Skip navigation
Currently Being Moderated

Spry Validation on Text field

Dec 17, 2012 10:56 AM

Tags: #text #field #spry #only #characters #validation

Hi, I am trying to figure out how to validate a text field so there are no spaces allowed only alph characters.

 

Here is my spry validaton field.

 

var sprytextfield6 = new Spry.Widget.ValidationTextField("spryRegisterLastname");

 

I've been reeding about the useCharacter mask, How would I go about using that. Like So?

 

var sprytextfield6 = new Spry.Widget.ValidationTextField("spryRegisterLastname", "none", {characterMasking: /dA-Z/ ,useCharacterMasking:true, validateOn:["blur", "change"]});

 

When I use the above code it does not work.

 

Any help would be appreciated

 

Winrol

 
Replies
  • Currently Being Moderated
    Dec 17, 2012 4:50 PM   in reply to winrol

    First create a little JavaScript function that contains a regular expression ( see here http://regexlib.com/?AspxAutoDetectCookieSupport=1) to validate that there are no spaces

    <script>

    function ValidateNoSpaces(value) {

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

    }

    </script>

    Then apply a custom validation to the constructor

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

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 17, 2012 10:42 PM   in reply to winrol

    It is best to use a regular expression. Think of a name like 'de la Rue'. Have a look at the last example here http://regexlib.com/Search.aspx?k=surname&c=-1&m=-1&ps=20

     

    for the second part of your question, add the highlighted line

      <span id="spryRegisterLastname">

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

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

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

        <span class="textfieldInvalidFormatMsg">Not the required format.</span>

      </span>

     
    |
    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