This javascript is working IE but not working in FIreFox, validating text fields.
var dealerid = new keybEdit('abcdefghijklmnopqurstuvwxyz01234567890 ','Alpha-numeric input only.');
var dealinit = new keybEdit('abcdefghijklmnopqurstuvwxyz01234567890 ','Alpha-numeric input only.');
var dealername = new keybEdit('abcdefghijklmnopqurstuvwxyz ','Alphabets input only.');
var rank = new keybEdit('01234567890','Numeric input only.');
void function setEvents() {
document.getElementById(dealerid)onkeypress = new Function('editKeyBoard(this,dealerid)');
document.all.dealinit.onkeypress = new Function('editKeyBoard(this,dealinit)');
document.all.dealername.onkeypress = new Function('editKeyBoard(this,dealername)');
document.all.rank.onkeypress = new Function('editKeyBoard(this,rank)');
}
Expand|Select|Wrap|Line Numbers
- function keybEdit(strValid, strMsg) {
- var reWork = new RegExp('[a-z]','gi'); // Regular expression\
- // Properties
- if(reWork.test(strValid))
- this.valid = strValid.toLowerCase() + strValid.toUpperCase();
- else
- this.valid = strValid;
- if((strMsg == null) || (typeof(strMsg) == 'undefined'))
- this.message = '';
- else
- this.message = strMsg;
- // Methods
- this.getValid = keybEditGetValid;
- this.getMessage = keybEditGetMessage;
- function keybEditGetValid() {
- return this.valid.toString();
- }
- function keybEditGetMessage() {
- return this.message;
- }
- }
- void function editKeyBoard(objForm, objKeyb) {
- strWork = objKeyb.getValid();
- strMsg = ''; // Error message
- blnValidChar = false; // Valid character flag
- // Part 1: Validate input
- if(!blnValidChar)
- for(i=0;i < strWork.length;i++)
- if(window.event.keyCode == strWork.charCodeAt(i)) {
- blnValidChar = true;
- break;
- }
- // Part 2: Build error message
- if(!blnValidChar) {
- if(objKeyb.getMessage().toString().length != 0)
- //alert('Error: ' + objKeyb.getMessage());
- alert(objKeyb.getMessage());
- window.event.returnValue = false; // Clear invalid character
- objForm.focus(); // Set focus
- }
- }