Text field with 2 word minimum

Posted on 2011-05-10
Last Modified: 2012-05-11
I am using the Spry framework within dreamweaver (cs4) to validate a html form.  I have a text field that must have 2 words in it to work properly.  It can have more than two.  I would like to allow for more than one space between words and spaces before the string if possible.  

Since the rest of the form is validated using Spry, the OnSubmit function of the form is not used, and per my understanding is blank for spry to work properly.  I have heard there was a way to use another script in tandem with spry to accomplish this.  

So to be clear, I just need to validate one text field in a form to have at least 2 words, without destroying the existing spry validation.  

Question by:Large_Farva
    LVL 75

    Accepted Solution


    something like

    function validatetextField(value, options) {
      return /^((\b[a-zA-Z]{2,40}\b)\s*){2,}$/i.test(value);

    var sometextField = new Spry.Widget.ValidationTextField("someTextField", "custom", {pattern: null, validation: validateTextField, validateOn:["blur"]});

    LVL 9

    Expert Comment

    the regex could be simpler:

    return /^\w{2,}\s+\w{2,}/i.test(value);

    Featured Post

    Course: Create Mobile App Prototypes with Adobe XD

    This is a project-based course: we go through all the steps of creating a prototype from start to finish, using all the tools and features currently available in Adobe XD. You can complete the course in less than a day, plus all project files and fonts are included.

    Join & Write a Comment

    This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
    Introduction HyperText Transfer Protocol ( or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now