Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I need to change the phone format from +XX XXX XXX XXXX into +XXXXXXXXXXXXX. I have a code but everytime I change it it doesn't work locally.

const [phoneNumber, setPhoneNumber] = useState();
const validatePhone = phone => {
  if (!isValidPhoneNumber(phone)) {
    errors.phone = { type: 'required', message: 'not valid' };
    return;
  }
  delete errors.phone;
  clearErrors('phone');
};
return (
  <>
<PhoneInput
              international
              displayInitialValueAsLocalNumber
              defaultCountry="UA"
              className={classes.phone_input}
              value={phoneNumber}
              onChange={handlePhoneInputChange}
              name="phone"
              id="phone"
            />
)
question from:https://stackoverflow.com/questions/65939073/phone-format-in-react

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
199 views
Welcome To Ask or Share your Answers For Others

1 Answer

As I understand question you can do it in onChange handler like this:

const phone = '+49 123 123 123';
const phone2 = phone.replace(/s+/g,'');
console.log(phone);
console.log(phone2);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...