I would like to know if anyone has a simple HTML code for validating input "Text" values so that form will either not accept any non integer, non positive, non numeric value. I am open to suggestions for look-up tables but as the numeric quantity value could be 1-1000 it would make them unwieldy, similarly knocking back the order form (which could have multiple line orders) because one of the values does not fit works but is tiresome. Would prefer answer to be JAVA driven as I am building a WEB hosted E Shop which will work on and off the WEB and just use the WEB to submit/authenticate orders.
HTML can not validate any value entered into a form. You would have to use some sort of scripting engine like javascript.
Anyways here is some code that you can look at modifying for your purposes.
<BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
// isInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// By default, returns defaultEmptyOK if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
// the default behavior which is specified globally by
// defaultEmptyOK.
// If emptyOK is false (or any value other than true),
// the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//
// EXAMPLE FUNCTION CALL: RESULT:
// isInteger ("5") true
// isInteger ("") defaultEmptyOK
// isInteger ("-5") false
// isInteger ("", true) true
// isInteger ("", false) false
// isInteger ("5", false) true
function isInteger (s)
{ var i;
if (isEmpty(s))
if (isInteger.arguments.length == 1) return defaultEmptyOK;
else return (isInteger.arguments[1] == true);
// Search through string's characters one by one
// until we find a non-numeric character.
// When we do, return false; if we don't, return true.
for (i = 0; i < s.length; i++)
{
// Check that current character is number.
var c = s.charAt(i);
if (!isDigit(c)) return false;
}
// All characters are numbers.
return true;
}
// isSignedInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if all characters are numbers;
// first character is allowed to be + or - as well.
//
// Does not accept floating point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// EXAMPLE FUNCTION CALL: RESULT:
// isSignedInteger ("5") true
// isSignedInteger ("") defaultEmptyOK
// isSignedInteger ("-5") true
// isSignedInteger ("+5") true
// isSignedInteger ("", false) false
// isSignedInteger ("", true) true
function isSignedInteger (s)
{ if (isEmpty(s))
if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
else return (isSignedInteger.arguments[1] == true);
else {
var startPos = 0;
var secondArg = defaultEmptyOK;
if (isSignedInteger.arguments.length > 1)
secondArg = isSignedInteger.arguments[1];
// skip leading + or -
if ( (s.charAt(0) == "-") | | (s.charAt(0) == "+") )
startPos = 1;
return (isInteger(s.substring(startPos, s.length), secondArg))
}
}
// isPositiveInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if string s is an integer > 0.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function isPositiveInteger (s)
{ var secondArg = defaultEmptyOK;
if (isPositiveInteger.arguments.length > 1)
secondArg = isPositiveInteger.arguments[1];
// The next line is a bit byzantine. What it means is:
// a) s must be a signed integer, AND
// b) one of the following must be true:
// i) s is empty and we are supposed to return true for
// empty strings
// ii) this is a positive, not negative, number
// isNonnegativeInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if string s is an integer >= 0.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function isNonnegativeInteger (s)
{ var secondArg = defaultEmptyOK;
if (isNonnegativeInteger.arguments.length > 1)
secondArg = isNonnegativeInteger.arguments[1];
// The next line is a bit byzantine. What it means is:
// a) s must be a signed integer, AND
// b) one of the following must be true:
// i) s is empty and we are supposed to return true for
// empty strings
// ii) this is a number >= 0
Bookmarks