Home > front end >  sign isn't getting stored in mysql database
sign isn't getting stored in mysql database

Time:08-22

i am using Laravel and Angular. I have a an input field for phone number where is mandatory. But sign isn't getting stored in database.

<div >
   <label for="mobilenumber"><i ></i></label>
   <input type="number" formControlName="phone_number"  name="phone" id="mobilenumber" placeholder="Phone number" required="" control-id="ControlID-4">
</div>

phone_number: new FormControl(null, [Validators.required]),

Laravel Backend Code

public function CustomerRegister()

    {

        $inputs = $this->request->all();

        $v = Validator::make($inputs, [

            'email' => 'required|string|max:50',

            'password' => 'required|confirmed',

            'password_confirmation' => 'required',

            'first_name' => 'nullable|string|max:100',

            'last_name' => 'nullable|string|max:100',

            'phone_number' => 'nullable|max:15',

            'postcode' => 'nullable|string|max:15',

            'abn' => 'nullable|string|max:15',

            'state' => 'nullable|string|max:15',

        ]);

Phone Number datatype in database is varchar(50) and collation is utf8_general_ci

CodePudding user response:

It would be best to store the number as an integer, then when displaying the number or using the number, prepend " ". There is no way to limit the characters used in a text field.

CodePudding user response:

You can store the phone number in a VARCHAR column (text), and you can enforce the valid pattern using a regular expression. For example:

create table t (
  phone varchar(20) 
  check(phone regexp '[0-9\ \-] ')
);

See examples on how it accepts and rejects values at db<>fiddle.

Note: The regular expression pattern above is just an example that accepts digits, plus signs, and dashes (in any order). You can modify the pattern as needed to tailor it to your specific needs.

  • Related