1: $(function () {
2: $("#bt").click(function() {
3: var text = $("#text").val();
4: var res = text.match(/\d{3}-\d{4}-\d/);
5: if (res != null) {
6: alert(true);
7: }
8: else {
9: if (text.length == 8) {
10: alert(text.replace(/(\d{3})(\d{4})(\d)/, "$1-$2-$3"));
11: }
12: }
13: });
14: });
本当はstring.insert的なものがあればとか思ったのだけれどもないので。
簡易的なものだけれども電話番号とかもいけそう。
投稿日時 : 2011年9月14日 23:19