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

Hi

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.


Thx

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

Open in new window

bigmikey88Asked:
Who is Participating?
 
_agx_Commented:
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).
<cfform>
	<cfinput type="text" 
		name="myfilename" message="Invalid characters for filenames found" 
		pattern="^[a-zA-Z0-9-]+$" 
		validateat="onSubmit" 
		validate="regular_expression" required="yes">
	<cfinput type="submit" name="submitButton">
</cfform>

Open in new window

0
 
_agx_Commented:
> I about to run out the door,

    I _am_ about to run out the door   (hence the bad spelling ;-)
0
 
bigmikey88Author Commented:
Excellent.  That worked perfectly.  Thank you very much.
0
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.