1

I need to create form input field for inputing bank account number. Than number has max = 18 number and min 18 numbers.

algorithm is next (3+13+2)

So i cant use clasic input text box i need special text box where i will have slash that separates that numbers like on screenshot:

enter image description here

How can i create textbox like above using javascript and html

Ivan
  • 5,139
  • 11
  • 53
  • 86

2 Answers2

2

This is very similar to this question: How to implement an input with a mask

The selected answer includes a link to a jQuery plugin that would work like this for your example:

$(function(){
    $("#field").mask("999 - 9999999999999 - 99");
});

Of course javascript can't solve everything and inputs should be validated server side as well.

Community
  • 1
  • 1
coyotte508
  • 9,175
  • 6
  • 44
  • 63
1

sometime ago I used a pluggin named "formatter.js" it is really easy to use, I will give you and example:

var formatted = new Formatter(document.getElementById('elementToFormat'), {
  'pattern': '{{999}}-{{9999999999999}}-{{99}}',
  'persistent': true
});

you can find that library to download and find the documentation in the following link, here or you can install that with bower

bower install formatter
Dlanor
  • 266
  • 2
  • 13