Answered by:
Ability to force digit formatting for a Reservation Number.

Question
-
Ability to force digit formatting for a Reservation Number. reservation number should be 8 digits and need to add validation to make sure the number can only be 8 digits.
how to do it in crm
Wednesday, October 13, 2010 12:13 PM
Answers
-
Thank you, what is the user wants 8 to 10 digits , rather than only eight,
how to check if less than 8 or greater than 10
let me know.
- Marked as answer by CRMAG Wednesday, October 20, 2010 12:52 PM
Wednesday, October 13, 2010 2:47 PM
All replies
-
Hi CRMAG
You can add field level validation by applying a little javascript to the onChange event of the CRM attribute you wish to control.
This script checks the data on entry against a regular expression and alerts the user if it does not match the format specified (in this case 8 numbers only).
I often use this technique for fields such as bank account numbers (8 numerical digits only) or sort codes (xx-xx-xx) etc
Here's the code, You just need to replace my 'new_attributename' with yours, and away you go.
You can also change the "quoted text" to return whatever message to the user you'd like.
Hope this helps :)//Regular Expression for, "8 Numerical digits only" var 8numFormat=/^\d{8}$/ //Check For Data on entry if (crmForm.all.new_Attributename.DataValue != null) //if data exists, check it's format against the expression { if (crmForm.all.new_Attributename.DataValue.search(8numFormat)==-1) //if it does not match, Alert the user and clear the data for re-input { alert("Please enter a valid number using 8 numerical digits"); crmForm.all.new_Attributename.DataValue = null; } }
Our company - XT BASE
My LinkedIn- Proposed as answer by Craig Hamer Wednesday, October 13, 2010 2:23 PM
- Edited by Craig Hamer Wednesday, October 13, 2010 2:23 PM error in code
Wednesday, October 13, 2010 2:23 PM -
Thank you, what is the user wants 8 to 10 digits , rather than only eight,
how to check if less than 8 or greater than 10
let me know.
- Marked as answer by CRMAG Wednesday, October 20, 2010 12:52 PM
Wednesday, October 13, 2010 2:47 PM -
No Problem, Just change the Regular expression that it tests against
from /^\d{8}$/
to /^\d{6,12}$/ (Also don't forget to update the alert text)
The code pretty much works for most validation requirements, You just need to tweak the Expression or cut/paste an new one in (as required).
If you have any other validation scenarios, There's a huge library of them here to play with :)Cheers
Craig
Our company - XT BASE
My LinkedInWednesday, October 13, 2010 3:41 PM -
var str = crmForm.all.new_Attributename.DataValue;
if ((str.length <= 7) && (str.length >= 11))
{
alert("Please enter a valid number using 8 numerical digits");
return false;
}Wednesday, October 13, 2010 3:44 PM -
... Yep, that will get you halfway there, however users can still save the record with incorrect data after the error message has alerted them.
therefore the validation fails.
the result has to include crmForm.all.new_Attributename.DataValue = null so that users are forced to enter to correct data.
Cheers
Craig
Our company - XT BASE
My LinkedInWednesday, October 13, 2010 4:01 PM