0

Firstly, being extremely honest I have minimal knowledge of Javascript and jQuery.

I have been working on a webite and have used a smart form plugin to create an order form. It has an option to add in javascript. I have created one to restrict date selection on a datepicker tool.

However I'm having trouble with trying to restrict the number of characters to 11 in a particular field. I would also like to restrict it to only numbers, letters and /.

It provides me with the below code to edit and use.

(function(){
    var javaObject = {
        AfterFormLoaded: function(jQueryFormReference) {},
        BeforeFormSubmit: function(formData, jQueryFormReference) {}
    };
    return javaObject;    
})  

If anyone is able to help or point me in the right direct it would be a massive help.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
dw87
  • 1
  • 2
    You can directly use the max and minlength property attribute of html input fields. No need to add separate script for it. – Nagama Inamdar Jun 10 '16 at 10:19

2 Answers2

2

You can use the default attributes of HTML input fields.

Max length and Min length

Following is the example of code to make use of the attributes.

<input type="text" maxlength="10" placeholder="test field" />

There is no need to add Javascript explicitly unless required.

Nagama Inamdar
  • 2,851
  • 22
  • 39
  • 48
1

You don't have to use Javascript for this one. Just use the maxlength property (html). For example, if you want a text input with max of 10 chars:

<input type="text" name="my_text" maxlength="10">
Yotam Salmon
  • 2,400
  • 22
  • 36