Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cfinput validation or mask?

New Here ,
Jan 07, 2011 Jan 07, 2011

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

1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 10, 2011 Jan 10, 2011

I wouldn't've suggested it if it wouldn't work 😉

prospect|(?:\d{6})


--

Adam

Translate
Enthusiast ,
Jan 07, 2011 Jan 07, 2011

You could use the regular expression validation feature of CFINPUT.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 07, 2011 Jan 07, 2011

Definetly not a mask.  Probably custom js.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 09, 2011 Jan 09, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 10, 2011 Jan 10, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 10, 2011 Jan 10, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 10, 2011 Jan 10, 2011

I wouldn't've suggested it if it wouldn't work 😉

prospect|(?:\d{6})


--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 10, 2011 Jan 10, 2011

Works great!

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 10, 2011 Jan 10, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 10, 2011 Jan 10, 2011
LATEST

I hope the preceding poster is ME.

I work through it Adam...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources