note 92247 deleted from function.is-numeric by crell

From: Date: Mon, 18 Apr 2022 14:52:24 +0000
Subject: note 92247 deleted from function.is-numeric by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218266@lists.php.net to get a copy of this message
Note Submitter: codeslinger at compsalot dot com ---- if speed is important, the liberal use of regex should be avoided, especially complex ones like those here. For most purposes, this will be sufficient and has the advantages of both speed and clarity. $BoolResult = empty(trim($Test, '+-.,0123456789')); If the $Test contains any character that is not a valid part of a number the remaining string will not be empty. if you want to be more restrictive of the '+-' then you can use a separate trim for that and nest it. Keep in mind that some notations pt the sign to the right of the number instead of to the left. Depending upon your specific application you can also choose to ignore spaces and allow for 'e' notation. I also use this approach when testing for other character sets such as Hex.

« previous php.notes (#218266) next »