0

How can i add pattern="[0-9]+" to the div in this js code ?

var max_fields      = 10; //maximum input boxes allowed
var wrapper         = $(".input_fields_wrap"); //Fields wrapper
var add_button      = $(".add_field_button"); //Add button ID

var x = 1; //initlal text box count
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
if(x < max_fields){ //max input box allowed
    x++; //text box increment
    $(wrapper).append('<div class="delivery-num-input"><input type="text"  pattern="[0-9]+" class="form-control delivery_number_plus"/><a href="#" class="remove_field btn btn-sm btn-danger">Remove</a></div>'); //add input box
}
});
2
  • 1
    What do you mean when you say "add to the div"? Commented Jul 4, 2017 at 9:14
  • @Shubham I guess pattern property is only applicable to input types, isn't it? Commented Jul 4, 2017 at 9:18

1 Answer 1

0

As it's said here. You can add programmatically the pattern to the input like this:

var regex = /\d+/;
var element = wrapper.find('input');
element.setAttribute("pattern", regex.source);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.