Skip to content

Instantly share code, notes, and snippets.

@thenixan
Created May 24, 2017 14:47
Show Gist options
  • Save thenixan/398da8376228fecb324925b650c11e92 to your computer and use it in GitHub Desktop.
Save thenixan/398da8376228fecb324925b650c11e92 to your computer and use it in GitHub Desktop.
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