php - Symfony validate telephone in form field -
i have symfony 2.6 , form personal information in form field telephone, rhis
+38 (918) 280-1594
and if developer write "_" or more digits, space. how in action check ? developer write
+38 (918) 2 801_594
and set in db
+38(918)2801594
what processes , decisions or bundles solve problem?
->add('telephone', null, array('label' => 'telephone', 'max_length' => 255, 'required' => false)); $builder->get('telephone')->addmodeltransformer(new callbacktransformer( // transform <br/> \n textarea reads easier function ($originaldescription) { return preg_replace('/[^0-9()]+/', "", $originaldescription); }, function ($submitteddescription) { // remove html tags (but not br,p) $cleaned = strip_tags($submitteddescription, '<br><br/><p>'); // transform \n real <br/> return str_replace("\n", '<br/>', $cleaned); } ));
but how works? write telephone 65454### , "#" write in db wrong. why not understand? , need determine number of digits (12 digits). maybe example please.
i post +30632666$$# , in db set +30632666$$# in form visible 30632666 need in db, need set in database correct telephone , limit 13 chars - 1 "+" , 12 - digital
after installing misdphonenumberbundle, can use bundle's validator:
use doctrine\orm\mapping orm; use misd\phonenumberbundle\validator\constraints misdassert; /** * @orm\entity * @orm\table */ class entity { // ... /** * @orm\column(type="string", length=50) * @misdassert\phonenumber() */ private $phone; }
Comments
Post a Comment