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

Validate Identifier string (MAC address) on Android #752

Open
avdyushin opened this issue Dec 1, 2023 · 0 comments
Open

Validate Identifier string (MAC address) on Android #752

avdyushin opened this issue Dec 1, 2023 · 0 comments

Comments

@avdyushin
Copy link
Contributor

Describe the bug
A clear and concise description of what the bug is.

Currently on iOS we check if Identifier is a valid UUID (done automatically by NSUUID object).
However on Android we just use raw string value. We can check if it's a valid MAC address as well.

How to fix, some ideas from @Daeda88

private val regex = "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$".toRegex()
fun main() {
    println("3D:F2:C9:A6:B3:4F".asValidIdentifier())
}

private fun String.asValidIdentifier(): String? = if (regex.matches(this)) {
    this
} else {
    null
}

or

private fun String.asValidIdentifier(): String? = regex.matchEntire(this)?.let {
    it.groupValues[0]
}

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

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

1 participant