2017-12-22 53 views
0

私はthieの携帯番号フィールドのための携帯電話の例とサードパーティ製のパッケージの多くを見てきました。djangoの携帯電話番号の正規表現

+ COUNTRY_CODE、またはスペース(これら3つは任意である)PHONE_NUMBER(分範囲番号= 8、maxは13である)EG :+65、98654578

のいずれかに基づいてしかし、私が欲しいのはこれです私はそれがうまくいかないと思います。 :私が作ったWhat's the best way to store Phone number in Django models

phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$', message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.") 
phone_number = models.CharField(validators=[phone_regex], max_length=17, blank=True) # validators should be a list 

一つがこれです:

mobile_regex = RegexValidator(regex=r'^\+?1?\d{1-3}?\,?\s?\d{8-15}$', message="Phone number must not consist of space and requires country code. eg : +6591258565") 

しかし、それは仕事をdoesntの。私は何か悪いことをしましたか?あなたが代わりにコンマのダッシュを使用して、あなたも一緒に+と国コードをキャプチャしたいあなたの命令与えてくれ

+0

可能な複製モバイル番号検証用](https://stackoverflow.com/questions/22378736/regex-for-mobile-number-validation) – Sayse

答えて

1

を助けてください、この正規表現は、私の作品:

^(\+\d{1,3})?,?\s?\d{8,13}

[正規表現の
関連する問題