Text field with 2 word minimum

Posted on 2011-05-10
Medium Priority
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

Michel Plungjan earned 2000 total points
ID: 35735496

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"]});


Expert Comment

ID: 35988222
the regex could be simpler:

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
Suggested Courses

829 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