numeric validation

Posted on 2011-10-26
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 ?
Question by:web5dev7
    LVL 51

    Accepted Solution

    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;		
          <!--- note, added a mask to remove non-numeric chars typed --->
    	<cfinput type="text" name="empid" 
    		message="Please submit a 7 digit numeric value" 
    		size="10" />
         <input type="submit">

    Open in new window


    Author Closing Comment

    works great, thanks!

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
    This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now