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
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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.