Sunday, November 30, 2008

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

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-input--tp20752566s27240p20761455.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

No comments: