?
Solved

numeric validation

Posted on 2011-10-26
2
Medium Priority
?
390 Views
Last Modified: 2012-05-12
I have a required form field that accepts only a 7 digit numeric value:

<cfinput type="text" maxlength="7" required="yes" validate="numeric" name="empid" message="Please submit a 7 digit numeric value" value="#cookievalue#" size="42" />

I want to prevent users from entering 7 of the same number like 0000000 or 1111111 or 2222222, etc., etc.  

What would be the simplest way to do that ?
0
Comment
Question by:web5dev7
2 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 37035539
One way is with onValidate. Use a regex to ensure the value is exactly 7 digits and to identify repeating numbers

<!--- test value  --->
<cfset cookievalue = repeatString("0",7)>

<script type="text/javascript">
	function isValidEmpId(frm, fld, value) {
		var isSevenDigits = /^(\d){7,7}$/.test(value);
		var isNonRepeating = !/([0-9])\1{6,}/.test(value);
		return isSevenDigits && isNonRepeating;		
	}
</script>
<cfform>
      <!--- note, added a mask to remove non-numeric chars typed --->
	<cfinput type="text" name="empid" 
		mask="9999999"
		maxlength="7" 
		required="yes" 
		onValidate="isValidEmpId" 
		message="Please submit a 7 digit numeric value" 
		value="#cookievalue#"
		size="10" />
	
     <input type="submit">
</cfform>

Open in new window

0
 

Author Closing Comment

by:web5dev7
ID: 37041513
works great, thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question