Skip navigation
Currently Being Moderated

Spry custom validation for particular word or any number

Jun 26, 2012 7:38 AM

I currently have the following for Spry validation of a particular text box:

 

 

<script type="text/javascript" src="includes/spry/SpryValidationTextField.js"></script>
<script type="text/javascript" src="includes/spry/SpryValidationSelect.js"></script>
<script type="text/javascript" src="includes/spry/SpryValidationTextarea.js"></script>
<script type="text/javascript" src="includes/spry/SpryValidationPassword.js"></script>
<script type="text/javascript" src="includes/spry/SpryValidationConfirm.js"></script>

<input id="spryuses" type="text" size="15" maxlength="15" name="uses" value="Unlimited" />
 var spryuse = new Spry.Widget.ValidationTextField("spryuses", "none", {useCharacterMasking:true, validateOn:["change"]}); 

 

I want the validation to limit the input to the word "Unlimited" or any number.

 

How can I do this with Spry? I could not find an example that's close enough for my limited knowledge.

 
Replies
  • Currently Being Moderated
    Jun 26, 2012 8:01 AM   in reply to Jeffshead1

    <!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", {validateOn:["blur"], pattern:"Unlimited"});

    </script>

    </body>

    </html>

    Gramps

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 26, 2012 8:56 AM   in reply to Jeffshead1

    <!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 /^(Unlimited)|[0-9]+$/.test(value)

        }

    </script>

    </body>

    </html>

    Gramps

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 26, 2012 6:05 PM   in reply to Jeffshead1

    for all numbers (0-hunderedsandthousandsetc)

    return /^(Unlimited|unlimited|[0-9]+)$/.test(value)

    for single numbers (0 to 9 only)

    return /^(Unlimited|unlimited|[0-9])$/.test(value)

    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