Skip to content

Region name validation? #569

Answered by Velfi
josb asked this question in Q&A
Jul 5, 2022 · 2 comments · 6 replies
Discussion options

You must be logged in to vote

In the Rust SDK, regions are just a special newtype for a Cow<'static, str>. We don't validate them in the client. Instead, we rely on the server to validate them.

You can see a list of valid regions here. You could hardcode that list into your app and check that user input matches one of them.

Alternatively, you could check that user input conforms to the general shape of a Region:

const PREFIX: &[&str] = &[
    "us",
    "af",
    // etc..
];

const MIDDLE: &[&str] = &[
    "east",
    "west",
    // etc...
];

fn validate_region(maybe_region: &str) -> bool {
    let mut parts = maybe_region.split("-");
    let prefix_is_valid = match parts.next().as_ref() {
        Some(prefix) => PREFIX.

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
6 replies
@Velfi
Comment options

@Velfi
Comment options

@josb
Comment options

@Velfi
Comment options

@josb
Comment options

Answer selected by Velfi
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants