Home > Domino Tips > Developer > Other > You can force numbers-only entries
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

OTHER

You can force numbers-only entries


Steve Kunstman
12.02.2002
Rating: -4.00- (out of 5) Hall of fame tip of the month winner


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


The following Javascript only allows a user to enter numbers in a field, and also limits the number of digits he/she can enter.

It works by constantly checking the field value via the setTimeout method every .05 seconds, removing non-numeric characters, and truncating the length if necessary.

This works in Notes R5 and above, INCLUDING in the client !

Remember to include the clearTimeout statement in the field's onBlur event, or the function will keep on running until the user exits the form.



Code

In the JSHeader

//Declare Global variables
var fName = ""
var nLen = 0

function limitField( f, n){
 // Transfer local variables to globals
 fName = f;
 nLen = n;
 limitLength();
}

function limitLength(){
 if (fName != "" && nLen > 0){
  with (document.forms[0].elements[fName]){
   v  = value
   v = numsOnly(v)
   if (v.length > nLen) {
    value = v.substr(0,nLen)
   }else{
    value = v
   }
   timerID = setTimeout("limitLength()", 50);
  }
 }
}

function numsOnly (inString) {
 // Removes all non-numeric chars
 var s = inString
 var nVals = "1234567890";     // acceptable chars; add + - . if floating values desired
 var i;
 var tmp = "";
 // Search through string and append to unfiltered values to tmp.
 for (i = 0; i < s.length; i++) {
  var c = s.charAt(i);
  if (nVals.indexOf(c) != -1){
   tmp += c;
  }
 }
 return tmp;
}


Example: 

Field onFocus event
limitField(this.name, 10)

Field onBlur event
clearTimeout(timerID)

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
Other
How to apply XSL style sheets to XML views
Comparing replicas on clustered Lotus Domino servers
Creating a Lotus Notes view column categorized by month
Using the XMLHTTP object for integration with Domino or any RDBMS back end
Hiding field properties/data from DocProperties box
Export a view to Excel without coding
Prevent document deletion if there are response documents
Switching between test IDs quickly
AddParameter to a NotesXSLTransFormer
Using DXL (Domino XML) to review/modify documents

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts