solarisuser Posted July 17, 2007 Share Posted July 17, 2007 Hi All, I'm asking for someone to enter a mac address, and it has to be in the format NN-NN-NN-NN-NN-NN They are entering the data in an <input type=text> field, and I was wondering if JS is the right solution to enforce this input as the user types it in (client-side validation). I'm doing client-side validation but I also would like client-side. Thanks Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted July 17, 2007 Share Posted July 17, 2007 You can do this with Javascript and a regular expression. function validateMAC(){ var field = document.getElementById("mac_fld_id"); var regexp = /([0-9]{2}-){5}[0-9]{2}/; // Now check field.value against the regexp, which I can't remember how to do // off the top of my head. I think it's regexp.test(field.value) } Quote Link to comment Share on other sites More sharing options...
paul2463 Posted July 17, 2007 Share Posted July 17, 2007 I think this is the way function validateMAC(){ var field = document.getElementById("mac_fld_id"); var regex = /([0-9]{2}-){5}[0-9]{2}/; // do the comparison, if we have a match if (regex.test(field)) { alert("Matches"); } else { alert("Does not match"); } } 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.