Sunday, November 30, 2008

[jQuery] Re: [validate] Allowing letters only in a text input?

Deron,

you would need to add the rule:
lettersonly: true // assuming you want name to be validated with
lettersonly

to any set of rules that you want this method to apply to

I have an example form set up here: http://ecommerce.i-cre8.com/admin/add-new-test.php
that shows how you can set up custom rules

Regards,

Dave Buchholz
I-CRE8 Internet Solutions
http://www.i-cre8.co.uk
Skype: I-CRE8


On Nov 30, 7:54 pm, deronsizemore <dsizemor...@gmail.com> wrote:
> Hi! Thanks for the quick reply. So, with this code added, will it make all
> fields letters only or is there a way for me to specify what field(s) I want
> to allow letters only?
>
> Thanks,
> Deron
>
>
>
> I-CRE8 wrote:
>
> > On Nov 29, 11:06 pm, deronsizemore <dsizemor...@gmail.com> wrote:
>
> >> The code is as follows:
>
> >> jQuery.validator.addMethod("lettersonly", function(value, element) {
> >>         return this.optional(element) || /^[a-z]+$/i.test(value);
>
> >> }, "Letters only please");
>
> >> My problem is that I'm not sure where to place the above code so that I
> >> can
> >> require only letters in one of my fields?
>
> > Hi,
>
> > you would please your code something like this:
>
> > <script type="text/javascript">
>
> > jQuery.validator.addMethod("lettersonly", function(value, element) {
> >         return this.optional(element) || /^[a-z]+$/i.test(value);
>
> > }, "Letters only please");
>
> >    $().ready(function() {
> >            $("#submit").validate({
> >         errorPlacement: function(error, element) {
> >              error.insertBefore(element);
> >          },
> >                 rules: {
> >                         name: {
> >                            required: true,
> >                            lettersonly: true // assuming you want name
> > to be validated with lettersonly
>
> >                         },
> >                         email: {
> >                                 required: true,
> >                                 email: true
> >                         }
> >                 },
> >                 messages: {
> >                         name: "Please enter your name",
> >                         email: {
> >                                 required: "Please enter your email",
> >                                 email: "Please enter a valid email
> > address"
> >                         }
> >                 }
> >         });
>
> >    });
> > </script>
>
> > Regards,
>
> > Dave Buchholz
> > I-CRE8 Internet Solutions
> >http://www.i-cre8.co.uk
> > Skype: I-CRE8
>
> --
> View this message in context:http://www.nabble.com/-validate--Allowing-letters-only-in-a-text-inpu...
> Sent from the jQuery General Discussion mailing list archive at Nabble.com.

No comments: