How to add a custom filter to a Spry text field validation

Development 24 July 2009 | 600 Comments

I have to say that I love the Adobe Spry Javascript framework. It is easy to use and simply just works. For most situations it comes with “widgets” for just about everything you need in your Ajax enabled web application.

One of my favorite widgets is the Text Validation one. With it you are able to validate just about everything the user enters and you will have full control of the input, even the pattern of the input.

But what about if you need a custom validation? According to the documentation you can use the “custom” parameter with a “pattern”. But if you use it, you actually apply a “pattern”, meaning applying a pattern of “pattern: “bbb” only allows the user to enter 3 alphabetical characters, but nothing more. Usually you want to have the user enter only alphabetical characters and not limiting the amount of chars.

In order to achieve this, you have the undocumented parameter called “characterMasking”! “characterMasking” combined with “usecharacterMasking: true” allows you to pass Regular Expressions to the text field you want to validate within the Spry syntax. Powerful stuff. It is beyond me, why Adobe has not updated their documentation on this. In any case, here is a example:

Say you want to allow only alphabetical character in lowercase and nothing else, you would use a syntax of;

var custom = new Spry.Widget.ValidationTextField(“myfield”,”custom”, {isRequired:true, hint:’some hint’, characterMasking: /[a-z]/, useCharacterMasking:true, validateOn:["blur", "change"]});

Would you like to only enable digits and spaces?

var sd = new Spry.Widget.ValidationTextField(“subdomain”,”custom”, {isRequired:true, hint:’Desired Subdomain’, characterMasking: /[\d\s]/, useCharacterMasking:true, validateOn:["blur", "change"]});

I guess you get the point. Combined with Regular Expression the Spry Text Validation Widget just entered into a new level of productivity.

Tagged in , , , , , , , , , , ,

600 Responses on “How to add a custom filter to a Spry text field validation”

  1. Your gps can be used in the countries mentioned if mapping for those areas are installed on your device. If they were not loaded on your device at purchase you should be able to purchase maps from Garmin.com for the areas you want to travel in.

  2. I have 5 beardies myself, there can be days where they won’t eat and there are days when they eat way to much. Have you switched the food source to a different source lately? Please be careful when force feeding them, they tend to get very resentful over it. I have taked to my pet store owner, and he says that they should eat every other day, and to make sure they are getting their vitamens, along with the calcium. also, try getting ahold of one the online bearded dragon breeders sometimes they can be helpfule, sorry i wish i can do more for ya .

  3. yes, there is a dog food out for nursing Moms, or give her a high protein dog food, and always make sure she is able to eat or drink anytime she wishes

  4. Thanks for the info, I will be checking in..thanks

  5. Fantastic!This Post is Inventive,tRight here are a Great deal of new Thought,it gives me inspiration.I Believe I will also inspired by you and Believe about more new Thoughts

  6. To get started on your own Healthy Meal Plans right away, download your FREE FAT LOSS Report on back2fit.

  7. Ccleaner.com says:

    I like it very much, Thanks a lot for sharing!!!

  8. nice read says:

    please can you translate into thai

  9. LuciaSKINNER says:

    All people deserve wealthy life time and loans or student loan would make it much better. Just because people’s freedom depends on money.

  10. Cesar Pooler says:

    This is just great, I really love it. We need more blogs like yours. You have great info and it is really good. I bookmarked this website and will come back. Thank you , ProXpro

  11. Takako Pomo says:

    Good article, Each and every and Just about every Stage is good Sufficient.Many thanks for sharing with us your wisdom.

  12. Celandine says:

    your style is pimpin

  13. Stacy Gold says:

    Temple Grandin is such a great motion picture, and such an exquisite and inspiring person! The 2010 Emmy Awards are terribly meaningful.

  14. Genuine you are Honest friend ! Thanks for taking time to write for readers like myself. I gone so crazy so mystified near like what is alli weight loss pills precisely then I watched what it really is I well read Genuine things from there this would be helpful for many people who want to loose weight fast.

  15. Desana says:

    I just found this blog and so far I can’t stop reading. I actually have to go to work now but I bookmarked it and when I get home today I’m gonna pick up right where I left off. Good stuff, really really good stuff!

  16. I really loved this post. You write about this topic very well. I really like your blog and I will definetly bookmark it! Keep up the interesting posts! :)

  17. free avatars says:

    Great post cheers, needed a few more pictures though.

  18. conveyancing says:

    Good information in your posting, I saw a report on a site last week about this same thing and since I am getting married in 3 weeks and the timing couldn’t have been better! Thanks for the post!

  19. Why didn’t congress question the AIG, CitiBank, Goldman Sachs, and all the other bank execs how they flew into Washington? I’m sure they didn’t take Greyhound! And they are getting 700 billion. This was just a cheap political ploy to try and embarrass the auto execs. By the way….how do congressmen get over to Iraq when they visit the troops? Private military jets that cost us a fortune, then they have a few hundred soldiers escort them – complete with helicopters, tanks, etc. to protect them.

  20. sex toys says:

    I have to, I’ve not been on this webpage in a long time… however it was anoda joy 2 c it’s such a vital topic & ignored by alot of people.

  21. Thank you for sharing this information it could not have come at a better time. The key to treatment is catching it early.

  22. Legalsounds says:

    Wow!, this was a top quality post. In theory I’d like to write like this too – taking time and real effort to make a good article… but what can I say… I procrastinate a lot and never seem to get something done

  23. Interesting article. Many thanks

  24. Amazing stuff,Thanks so much for this!This is very Helpful post for me. This will Certainly Heading to Support me in my projects .

  25. Thanks for sharing this article.

  26. Todd Bishop says:

    I certainly appreciate this post. We need more persons like you bringing value towards the community. Can I put this post on my blog? I’d give you credit and link back of course.

  27. Hi I found your site by mistake when i was searching yahoo for this acne issue, I must say your site is really helpful I also love the design, its amazing!. I don’t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site.

  28. I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your web site to look at the latest stuff you post.

  29. This is a good blog. Keep up all the work. I too love to blog. This is great everyone sharing opinions :)

  30. costumes says:

    I’m pleased someone was willing to sooner or later clear things up on this. I have puzzled over it frequently. :)

Leave a Reply