Alphanumeric Entries in Text Field Annomalies – Chars Stripped Leaving Numbers
-
Hello
CFF: Version 5.0.6Simple Problem
I have a Text Field where the user has to enter alphanumeric CCCNN (c=char n=numeric )
I am trying to mess with it using this snippet I got from the FAQ page(function(){ var text = 'fieldname75'; text = text.replace( /[\s\t\r\n]/g, '' ); // not needed but copied from FAQ return text.length;
})()`
now when it is :
BLANK it returns “1”
CCCNN it returns “7”
CCC10 it Returns “2”
CC123 it Returns “3”
12345 it returns “5”So it appears that somehow var text = ‘fieldname75’; is only passing Numerics in var text = ‘fieldname75’; when there is a numeric in the text field ?? and why does a blank field have a len value of 1 ??
But …
What I am trying to do is simplefunction () { var text = prompt("Please enter your Code format CCCNN C=Char N=Number", ""); var valarray = ['ASK10', 'ASK15', 'SHO10']; var disc if (text === "") { return 0; // Blank no Code Entered so no calc to do } else { // Check for valid code - is it in array .. only 12 valid codes if (valarray.indexOf(text) > -1) { // yes we have a valid code disc = text.substr(3); disc = parseInt(disc, 10); return disc; // the NN of CCCNN for Calculations } else { return 99; // Code entered but not valid no match to array }; }; } })()
Test at JSFiddle very hacky noddy script for 10 alphanumeric codes
https://jsfiddle.net/exclusiveor77/n3o8jftk/3/
- The topic ‘Alphanumeric Entries in Text Field Annomalies – Chars Stripped Leaving Numbers’ is closed to new replies.