February, 2017
preg_match for Japanese forms
郵便番号 /^[0-9]{3}-[0-9]{4}$/ if (preg_match(‘/^[0-9]{3}-[0-9]{4}$/’, $str)) { 電話番号 /^[0-9]{2,4}-[0-9]{2,4}-[0-9]{3,4}$/ if (preg_match(‘/^[0-9]{2,4}-[0-9]{2,4}-[0-9]{3,4}$/’, $str)) { Emailアドレス |^[0-9a-z_./?-]+@([0-9a-z-]+\.)+[0-9a-z-]+$| if (preg_match(‘|^[0-9a-z_./?-]+@([0-9a-z-]+\.)+[0-9a-z-]+$|’, $str)) { 全角空白のトリム /^ *(.*?) *$/u $str = preg_replace(‘/^ *(.*?) *$/u’, ‘$1’, $str); 半角+全角空白のトリム /^[\s ]*(.*?)[\s ]*$/u $str = preg_replace(‘/^[\s ]*(.*?)[\s ]*$/u’, ‘$1’, $str);
Posted in etc | Comments Off on preg_match for Japanese forms