• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Question about range of input field filed in HTML.

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have a question regarding the range of input field. Suppose, I created input field (debit card , in which I want 16 numbers , and space between every four number, means user easily put their debit card number which is of 16 bit numbers with space ), so I put input field = "number", but I easily put those numbers, but there is no restrictions, that only 16 numbers should be there ,( with space, space should be after every four number), how should do this? how to put these restrictions that only 16 numbers should be in input field and space after every four number?


 
Sheriff
Posts: 67699
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are only concerned with modern browsers, the HTML5 input element has a pattern attribute that you can use to specify a regular expression that must be adhered to.

If you need to support legacy browsers, then you'd need to write script that checks the pattern.
 
Bear Bibeault
Sheriff
Posts: 67699
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But to be honest, I wouldn't do it this way. As long as you get the 16 numbers, what do you care about the spaces? I'd let the user enter the 16 digits any way they wanted; with no spaces, with dashes, with any non-digit characters, whatever. Make it easy on the user, and write your code to make sure you get 16 digits -- anything else is unimportant.
 
"To do good, you actually have to do something." -- Yvon Chouinard
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic