Skyforum Posted July 5, 2012 Report Share Posted July 5, 2012 I have one field I need to restrict to accept only alphanumeric characters. I don't want to allow any spaces or hyphens etc. I would also like to specify the exclusion of specific characters (like the letter Q). I found this and I think it meets my need but do not know how to apply it. I am going to be using it in two different situations. One is for license plate numbers. Only want to allow letters and numbers. The other is in VIN numbers where I want the same restrictions but also want to add specific character restrictions, no Q or O (that's an oh, not a zero) are found in VIN numbers. Please help format it so I can place it in my footer of the datapage. I have tried adding it to my footer and I can;t seem to get it to work. Thanks function alphanumeric(plate) { var letterNumber = /^[0-9a-zA-Z]+$/; if((plate.value.match(letterNumber)) { return true; } else { alert("Only letters or numbers are allowed in this field"); return false; } } Quote Link to comment Share on other sites More sharing options...
ShWolf Posted July 13, 2012 Report Share Posted July 13, 2012 Hi, Insert following script into the footer of the DataPage. This is example for the VIN numbers. If you want to allow Q and O letters, just delete |Q|O from the code below. <script language="JavaScript"> function alphanumeric(v_plate) { if(!(v_plate.value.match(/[^0-9A-Z]|Q|O/))){ return true; } else { alert("Only letters or numbers are allowed in this field"); return false; } } v_b = document.getElementById('Submit'); v_b.onclick = function(){ if(alphanumeric(document.getElementById('INSERTYOURFIELDIDHERE'))) { v_b.submit(); } else { return false; } } </script>And replace INSERTYOURFIELDIDHERE with correct field id.Let me know if this helps. Quote Link to comment Share on other sites More sharing options...
Skyforum Posted July 14, 2012 Author Report Share Posted July 14, 2012 Very nice. Thank you! I'll load it up and report any problems back here. Thanks again... Quote Link to comment Share on other sites More sharing options...
Skyforum Posted July 14, 2012 Author Report Share Posted July 14, 2012 Doesn't seem to work... I don't even get an error. Would the fact that I have the field set to autocomplete create an issue? Quote Link to comment Share on other sites More sharing options...
bahar_vm Posted July 20, 2012 Report Share Posted July 20, 2012 What did you replace INSERTYOURFIELDIDHERE with? To verify your field id you can use Firebug which is developer add-on for Firefox browser. You can then inspect the element and find the id. In general, form element IDs in Submission forms are "InsertRecordFIELDNAME", replace FIELDNAME with yours. Form elements in Update forms and Details pages (only editable fields. Display Only fields do not have any ID) are "EditRecordFIELDNAME". Quote Link to comment Share on other sites More sharing options...
Skyforum Posted August 8, 2012 Author Report Share Posted August 8, 2012 I told you I was a newbie. Changed it to 'InsertRecordlic_plate' and it works great. Thank you very much. Quote Link to comment Share on other sites More sharing options...
Skyforum Posted August 8, 2012 Author Report Share Posted August 8, 2012 One more question. I have a license plate field as well as a vin field, both with their own needs in the same datapage. I tried adding the script in twice but there appears to be some conflict as i can only get one to work. I even tried changing the function name to no avail. (v_plate to l_plate). What am I doing wrong? Do I need to merge them into one somehow? Quote Link to comment Share on other sites More sharing options...
AngelYang Posted August 29, 2012 Report Share Posted August 29, 2012 Thank you for paying attention to this thread! I myself faced this trouble and I am an absolute newbie to javascript. With your help it gets easier. Quote Link to comment Share on other sites More sharing options...
ShWolf Posted August 29, 2012 Report Share Posted August 29, 2012 Hi, Try this code: <script language="JavaScript"> function checkAlpha1(v_plate){ if(v_plate.value.match(/[^0-9A-Z]|Q|O/)){ alert("Only capital letters or numbers are allowed in this field"); return false; } return true; } function checkAlpha2(v_plate){ if(v_plate.value.match(/[^0-9A-Z]|Q|O/)){ alert("Only capital letters or numbers are allowed in this field"); return false; } return true; } document.getElementById('Submit').onclick = function(){ if(!checkAlpha1(document.getElementById('INSERT_YOUR_FIELD_1_ID_HERE'))) return false; if(!checkAlpha2(document.getElementById('INSERT_YOUR_FIELD_2_ID_HERE'))) return false; } </script> And replace INSERT_YOUR_FIELD_1_ID_HERE and INSERT_YOUR_FIELD_2_ID_HERE with your field ids. Also change criterias in the script for fields, as you need. Let me know if this helps. lmooring 1 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.
Note: Your post will require moderator approval before it will be visible.