Can anyone help me write a Reg Exp for CFINPUT Validation to prevent special char


I have a Cold Fusion form using <CFinput>  and I need to validate that the field is only:

letters - upper and lower case are OK
numbers are OK
hyphens are OK

but no special characters like  / \.,?!  spaces  etc

This field will become the name of a file.


<cfinput type="text" name="myfilename" message="  " pattern="  " validateat="onSubmit" validate="regular_expression" required="yes">

Open in new window

Who is Participating?
I about to run out the door, but you could try something like the attached.  

However, you should also scrub the value on the server side as well.  So you are not depending on javascript only. I usually use a CF regex to replace all invalid characters with an underscore "_" (or something safe).
	<cfinput type="text" 
		name="myfilename" message="Invalid characters for filenames found" 
		validate="regular_expression" required="yes">
	<cfinput type="submit" name="submitButton">

Open in new window

> I about to run out the door,

    I _am_ about to run out the door   (hence the bad spelling ;-)
bigmikey88Author Commented:
Excellent.  That worked perfectly.  Thank you very much.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.