var posted: string; begin posted:= GetCgiVar('phone'); // posted from a form edit box with NAME='phone' if (IsNum(posted)) and (posted <= 16) then // accept phone number under 16 webwrite('Thank you, phone number accepted.') else webwrite('Phone number must not contain dashes or brackets.' + 'and must be shorter than 16 numbers long please.') end.In the above example, we check to see if the input is close to a correct phone number. Since some folks may live in countries with different length phone numbers, it is hard to verify the phone number is one hundred percent correct, so we just ensure that the phone number entered is under 16 characters and contains only numbers.
See also the IsNumSpace which allows numbers and spaces, and the IsNumSpaceDashBrack which allows numbers, dashes, and brackets. For database integrity, you might want to stick with numbers only.
var posted: string; begin // get a variable through POST/GET using GetCgiVar_S (security bypass). We allow // '@' symbol and '.' symbol in so we specify zero security as paramater posted:= GetCgiVar_S('email', 0); // posted from a form edit box with NAME='email' if IsEmail(posted) then webwrite('Thank you, email address accepted.'); end.
Sample functions and descriptions from the strfilter.pas unit are below:
// checks string for characters given as a parameter function ValidChars(s: string; CharSet: TCharSet): boolean; // Checks if email address format is correct or extremely close to correct. It is // impossible to check to see whether the email is 100 percent correct since new // domain name extensions are being added every year (.ws, .tk, .co.uk.org). // Does not use a whitelist. Just checks for general "within the ballpark" // correctness. Does not accept address such as John@localhost it must be in the // format john@domain.com or john.domain.ca etc.} function IsEmail(s: string): boolean; // alphabet and numbers only allowed function IsAlphNum(s: string): boolean; // alphabet, numbers, and space allowed function IsAlphNumSpace(s: string): boolean; // alphabet, numbers, space, and underscore allowed function IsAlphNumSpaceUscor(s: string): boolean; // alphabet, numbers, space, dash, and underscore allowed function IsAlphNumSpaceDashUscor(s: string): boolean; // alphabet, numbers, dash, and underscore allowed function IsAlphNumDashUscor(s: string): boolean; // alphabet, numbers, and underscore allowed function IsAlphNumUscor(s: string): boolean; // alphabet, numbers, and dash allowed function IsAlphNumDash(s: string): boolean; // numbers, dashes, brackets, plus sign allowed function IsNumDashBrackPlus(s: string): boolean; // numbers, dashes, brackets allowed function IsNumDashBrack(s: string): boolean; // numbers only function IsNum(s: string): boolean; // numbers and dashes allowed function IsNumDash(s: string): boolean; // numbers and spaces allowed function IsNumSpace(s: string): boolean; // numbers, dashes, and spaces allowed function IsNumDashSpace(s: string): boolean; // numbers, dashes, brackets, and spaces allowed function IsNumSpaceDashBrack(s: string): boolean; // alphabet only allowed (a..z A..Z) function IsAlph(s: string): boolean; // alphabet plus underscore and space allowed function IsAlphSpaceUscor(s: string): boolean; // alphabet plus dashes allowed function IsAlphDash(s: string): boolean; // alphabet plus dashes and spaces allowed function IsAlphDashSpace(s: string): boolean; // alphabet plus underscore allowed function IsAlphUscor(s: string): boolean; // alphabet plus space allowed function IsAlphSpace(s: string): boolean; // lower case alphabet allowed function IsLowAlph(s: string): boolean; // lower case alphabet plus space allowed function IsLowAlphSpace(s: string): boolean; // lower case alphabet plus underscore allowed function IsLowAlphUscor(s: string): boolean; // lower case alphabet plus space and underscore allowed function IsLowAlphSpaceUscor(s: string): boolean; // upper case alphabet allowed function IsUpAlph(s: string): boolean; // upper case alphabet and underscore allowed function IsUpAlphUscor(s: string): boolean; // upper case alphabet and space allowed function IsUpAlphSpace(s: string): boolean; // upper case alphabet, and underscores and spaces allowed function IsUpAlphSpaceUscor(s: string): boolean;