Good day. I add additional fields to the general settings page. See the picture. I make the first and second phone mandatory with required , and prescribe the pattern , but validation does not work, you can set any values. How can I fix this?

 function show_field_tel($number) { ?> <input name="tel_<?php echo $number?>" size="30" type="tel" placeholder="+7 (900) 123-45-67" <?php if ($number === 1 || $number === 2) echo 'required'?> pattern="\+7\s?[\(]{0,1}9[0-9]{2}[\)]{0,1}\s?((\d{3}[-]{0,1}\d{2}[-]{0,1}\d{2})|(\d{2}[-]{0,1}\d{3}[-]{0,1}\d{2}))" value="<?php echo get_option( "tel_$number" )?>" /><?php } 

enter image description here

    1 answer 1

    Forms with options in the WordPress admin panel are built in a mode without validation. Look at the html code and you will see something like

     <form method="post" action="options.php" novalidate="novalidate" _lpchecked="1"> 

    Validation of form fields with potions should be done using the callback sanitize_callback . Read more about it in Russian here .

    • Thank you very much! - Igor