Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevention from passing non-numeric signs #42

Closed
swiatrzyk opened this issue Dec 21, 2021 · 2 comments
Closed

Prevention from passing non-numeric signs #42

swiatrzyk opened this issue Dec 21, 2021 · 2 comments

Comments

@swiatrzyk
Copy link

swiatrzyk commented Dec 21, 2021

It would be great if the text field would remove non-numeric signs on phone paste (f.e. pasted tel. +48-123-123-123 to (48)-123-123-123 for pattern (##)-###-###-###) - so text field receives only numbers from pasted text and formats it accordingly.

@Tinamu
Copy link

Tinamu commented Jan 14, 2022

you always can use onReceive property to prevent typing anything but numbers
something like this

FormatTextField(
    unformattedText: $phone,
    placeholder: "900 000 00 00",
    textPattern: "### ### ## ##"
)
    .keyboardType(.numberPad)
    .onReceive(Just(phone)) { newValue in
        let filtered = newValue.filter { "0123456789".contains($0) }
        if filtered != newValue {
            self.phone = filtered
        }
    }

@luximetr
Copy link
Owner

@swiatrzyk Thank you for your idea. Will keep it in mind when will work on it in future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants