[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

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

0
bigmikey88
Asked:
bigmikey88
  • 2
1 Solution
 
_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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now