*/ public function rules(): array { /** @var PreregistrationPage $page */ $page = $this->route('publicPage'); $page->loadMissing('blocks'); $emailRule = (new Email) ->rfcCompliant() ->preventSpoofing(); return [ 'first_name' => ['required', 'string', 'max:255'], 'last_name' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'max:255', $emailRule], 'phone' => $page->isPhoneFieldEnabledForSubscribers() ? ['nullable', 'string', 'regex:/^[0-9]{8,15}$/'] : ['nullable', 'string', 'max:255'], ]; } /** * @return array */ public function messages(): array { return [ 'email' => __('Please enter a valid email address.'), 'phone.regex' => __('Please enter a valid phone number (8–15 digits).'), ]; } /** * @return array */ public function attributes(): array { return [ 'first_name' => __('First name'), 'last_name' => __('Last name'), 'email' => __('Email'), 'phone' => __('Phone'), ]; } protected function prepareForValidation(): void { $email = $this->input('email'); if (is_string($email)) { $this->merge([ 'email' => strtolower(trim($email)), ]); } /** @var PreregistrationPage $page */ $page = $this->route('publicPage'); $phone = $this->input('phone'); if (! $page->isPhoneFieldEnabledForSubscribers()) { $this->merge(['phone' => null]); return; } if (is_string($phone)) { $digits = preg_replace('/\D+/', '', $phone); $this->merge(['phone' => $digits === '' ? null : $digits]); } } }