This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

jprevot
jprevot

implement the mask to input eg for phone

KurtJensen
KurtJensen

I have found it is easier to let user enter however they want.

Then use model to strip to all numbers and then break in pieces and format before storing.

public function formatPhone()
{
    $pin = preg_replace ('/[^0-9]/i',"", $this->phone); // strip all but numbers
    if (!strlen($pin) == 10) return false;// Check for 10 digit phone number
    if (!$pin) return false;
    $area = substr($pin, 0, 3);
    $prefix = substr($pin, 3, 3);
    $station = substr($pin, 6, 4);
    $this->phone = '('.$area.')'.$prefix.'-'.$station;
}

Last updated

jprevot
jprevot

It is easier to implement such option jquery mask

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.