Welcome Guest, Not a member yet? Register   Sign In
Formatting Number with Regular Expression
#3

[eluser]tkaw220[/eluser]
Hello pickupman,

Your regex is not working for me. But I do get a working code from Dreamweaver forum:

$result = preg_replace('/(\\d{3})(\\d{3})(\\d{3})(\\d{1})/', '${1}-${2}-${3}-${4}', $phone_str);

However, this regex applied to string with exact length (ie., 10 digits in this case) but break if the string has different length, ie., 14 digits. Any idea on how to modify it so that it always add a dash after every 3 digits at any string length?

Thank you very much and have a nice day.

Best regards,
Edwin


Messages In This Thread
Formatting Number with Regular Expression - by El Forum - 03-03-2011, 08:56 AM
Formatting Number with Regular Expression - by El Forum - 03-03-2011, 09:05 AM
Formatting Number with Regular Expression - by El Forum - 03-03-2011, 08:40 PM
Formatting Number with Regular Expression - by El Forum - 03-03-2011, 10:52 PM
Formatting Number with Regular Expression - by El Forum - 03-04-2011, 12:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB