Created
May 24, 2017 14:47
-
-
Save thenixan/398da8376228fecb324925b650c11e92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.nixan.sandboxapp | |
import android.os.Bundle | |
import android.support.v7.app.AppCompatActivity | |
import android.widget.Button | |
import android.widget.EditText | |
import android.widget.Toast | |
import ru.nixan.regexpformatter.RegExpFormatter | |
class MainActivity : AppCompatActivity() { | |
val regExpFormatter = RegExpFormatter("\\d{3}-\\d{3}") | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
(findViewById(R.id.testEdit) as EditText).addTextChangedListener(regExpFormatter) | |
(findViewById(R.id.testEdit) as EditText).setRawInputType(regExpFormatter.inputType) | |
(findViewById(R.id.triggerButton) as Button).setOnClickListener { | |
if (regExpFormatter.check((findViewById(R.id.testEdit) as EditText).text.toString())) { | |
Toast.makeText(this, "OK", Toast.LENGTH_LONG).show() | |
} else { | |
Toast.makeText(this, "Incorrect", Toast.LENGTH_LONG).show() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment