Jump to content

[SOLVED] Number Input Mask


psychowolvesbane

Recommended Posts

I have created a form that has a input field that users can enter their 18 digit (Format: 6,4,4,4) NUS number (For those who don't know what that is its the National Union of Students in the UK), and I was hoping to try and add an input mask instead of the numeric validation I have already that doesn't find out if it's okay or not.

 

If that isn't possible then I might have a go at using 4 separate input fields instead.

 

What do you think, is it possible to do it the first way?

Link to comment
https://forums.phpfreaks.com/topic/101452-solved-number-input-mask/
Share on other sites

I would use - to separate them. Anyway how would I go about using that in an if statement when comparing the $NUSNum variable?

 

Something like this?

if (!preg_match('/[0-9]{6}[-]{0,1}[0-9]{4}[-]{0,1}[0-9]{4}[-]{0,1}[0-9]{4}[-]{0,1}/', $NUSNum))

 

I changed one of my Email validation masks to make this based on what you gave me.

Have you tested that?

 

you could use:

[, -_.|:]

etc, to cover all the bases, p.s. some of those may need escaping...

 

oh I just noticed:

/^[0-9]{6}[, ]{0,1}[0-9]{4}[, ]{0,1}[0-9]{4}[, ]{0,1}[0-9]{4}$/

that the last bit was'n needed!

p.s. this isn't checked, i'm here just to drink my coffee... and the theres a whole area dedicated to this subject next door...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.