Answer the question
In order to leave comments, you need to log in
How to validate the phone when placing an order in Bitrix?
Added a phone input mask, it works correctly. But if the user enters the phone number incompletely, it will remain so, for example, +7 (920) 333-__-__
I try to enter a regular expression in the order properties in the admin panel to check
/^[+][0-9] [(][0-9]{3}[)] [0-9]{3}[-][0-9]{2}[-][0-9]{2}$/
Answer the question
In order to leave comments, you need to log in
If the mask was made using InputMask , then at the front you can add field validation BEFORE saving the order
if ($(selector).inputmask("isComplete")){
//do something
}
<?
function OnSaleOrderBeforeSaved(\Bitrix\Main\Event $event)
{
/** @var \Bitrix\Sale\Order $order */
$order = $event->getParameter("ENTITY");
if ($order->isNew() ) {//Если проверка требуется только для нового заказа, а не при его редактировании
$propertyCollection = $order->getPropertyCollection();
$phoneProperty = $propertyCollection->getPhone();
$isPhoneValid = validatePhone($phoneProperty);
if (!$isPhoneValid) {
$event->addResult(new \Bitrix\Main\EventResult(
\Bitrix\Main\EventResult::ERROR,
new \Bitrix\Sale\ResultError('Текст ошибки', 'PHONE_PROPERTY_INVALID')
));
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question