psychowolvesbane Posted April 16, 2008 Share Posted April 16, 2008 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? Quote Link to comment Share on other sites More sharing options...
tinker Posted April 16, 2008 Share Posted April 16, 2008 if its client side then you'll need to use javascript, do a check on onchange or something? Quote Link to comment Share on other sites More sharing options...
psychowolvesbane Posted April 16, 2008 Author Share Posted April 16, 2008 Well I would like both client and server side in case people don't have JS enabled, so lets concentrate on server-side upon submission. Quote Link to comment Share on other sites More sharing options...
tinker Posted April 16, 2008 Share Posted April 16, 2008 regex could go a little like: /[0-9]{6}[, ]{0,1}[0-9]{4}[, ]{0,1}[0-9]{4}[, ]{0,1}[0-9]{4}[, ]{0,1}/ it'll be similar for both... p.s. they can use spaces or nothing instead of commies, you know what studies are like! Quote Link to comment Share on other sites More sharing options...
psychowolvesbane Posted April 16, 2008 Author Share Posted April 16, 2008 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. Quote Link to comment Share on other sites More sharing options...
tinker Posted April 16, 2008 Share Posted April 16, 2008 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... Quote Link to comment Share on other sites More sharing options...
psychowolvesbane Posted April 16, 2008 Author Share Posted April 16, 2008 It looks like it's worked in JS when I tried that so I'm assuming it will work just as fine with php. Quote Link to comment Share on other sites More sharing options...
tinker Posted April 16, 2008 Share Posted April 16, 2008 just thinking how you'd handle a replace to ensure continuity... /^([0-9]{6})([, ]{0,1})([0-9]{4})([, ]{0,1})([0-9]{4})([, ]{0,1})([0-9]{4})$/ but i'm not sure what would happen if a grouping was missing, i think it should be ok... Quote Link to comment Share on other sites More sharing options...
psychowolvesbane Posted April 16, 2008 Author Share Posted April 16, 2008 I ended up just using spaces between each grouping, also followed by giving the user a message beside the input to use spaces. Though the amount of people that cannot read signs properly in this day and age is horrendous! Quote Link to comment Share on other sites More sharing options...
tinker Posted April 16, 2008 Share Posted April 16, 2008 theres always two parts to a sign, the signifier and the signified, and i was so rightly informed the other day, it's all aboot perception... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.