Copy link to clipboard
Copied
Let me preface this with I am a newbie when it comes to ColdFusion.
I have a cfinput textbox that I want enforce the the entry of a six digit number or the word 'prospect', but nothing else.
How can I go about doing this?
Thanks
EDIT: Server is CF8
I wouldn't've suggested it if it wouldn't work 😉
prospect|(?:\d{6})
--
Adam
Copy link to clipboard
Copied
You could use the regular expression validation feature of CFINPUT.
Copy link to clipboard
Copied
Definetly not a mask. Probably custom js.
Copy link to clipboard
Copied
Hi,
If you want to restrict the user to enter only 6 characters, you could use " maxLength " attribute.
You could also use a Javascript function in this attribute "onValidate"; first get the first character, if its a number, check for the length (6) and loop through it for the length and check for each character is a number, or if its a word, check for PROSPECT.
Copy link to clipboard
Copied
Yikes! That'd be a lot of unnecessary work.
One can just use the native <cfinput> functionality to perform a regex validation for that.
--
Adam
Copy link to clipboard
Copied
Yes Adam, but he wants either one of these , a six digit number or a word PROSPECT, in this regEx will work??
Im sorry if i m wrong.
Copy link to clipboard
Copied
I wouldn't've suggested it if it wouldn't work 😉
prospect|(?:\d{6})
--
Adam
Copy link to clipboard
Copied
Works great!
Thanks
Copy link to clipboard
Copied
Cool. Do you understand how the regex works? I do kinda try not to give the actual answers here so people can work through the solution for themselves, but the preceeding poster kinda forced my hand a bit by questioning whether what I was saying was accurate.
If you're not already familiar with regexes, it'd be good, perhaps, if you nutted out why this is approach works. But, obivously, it's up to you 😉
--
Adam
Copy link to clipboard
Copied
I hope the preceding poster is ME.
I work through it Adam...