Answer the question
In order to leave comments, you need to log in
What should be the type of row in the database for a phone number consisting of only digits?
There is a row in the phone table, numbers in the form (000)-00-00-000 get there. Is there a way to have the DB clean up unwanted characters when they hit? It is necessary that the number gets there in the format 0000000000. The
mask for entering the number on the site cannot be disabled or changed.
Answer the question
In order to leave comments, you need to log in
As far as I understand, it is necessary not only to clean them for saving and subsequent convenient use, but also to return them to their place when transferring data back to the site for display or correction, right?
If so, then I suggest not to do anything with the field itself, let it be textual and with all sorts of garbage. And for use, create another, calculated, field in which to put the cleared and reduced to a numeric value.
Those. if currently available
CREATE TABLE users (
...
phone VARCHAR(255),
....
);
ALTER TABLE users ALGORITHM = INPLACE
ADD COLUMN phone_num BIGINT UNSIGNED AS (REGEXP_REPLACE(phone, '[^0-9], ''')) VIRTUAL,
INDEX idx_phone_num (phone_num);
What you want is not the job of the database. This work must be done in the program code prior to saving to the database
What should be the DB Row Type for numbers only?I assume that they meant "what data type to use for a cell to store numbers in the format 0000000000?". Most likely you will have to use a varchar, since the zeros at the beginning of the string will be stupidly ignored when converted to a number.
but there are numbers in the form (000) -00-00-000Badly
But I can’t disable or change the number input mask on the siteAnd it is not necessary, it is not necessary to decide on the forte. This is solved by means of the server language, node, puff, in short BEFORE entering data into the database.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question