|
-
Oct 4th, 2012, 05:03 AM
#2
Re: Number conver e.g 1.5k (k being thousand) to 1500
For regex, use the preg_match()
And a pattern like this might work:
Code:
/^[0-9][0-9\.,]*(k|b|m)?$/i
That is the first character should be a digit. Then followed by digits or dots or commas, for zero or more times. Then followed by "k" or "b" or "m" or nothing.
Am not good in regex. Maybe you'll get a better pattern than this. 
Example:
PHP Code:
$num = "100,1230.0m";
$pattern = "/^[0-9][0-9\.,]*(k|b|m)?$/i";
if (preg_match($pattern, $num)) {
echo "Correct form";
} else {
echo "Incorrect form";
}
Hope it helps
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|