mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Invite by msisdn. Error 500 from matrix.org though (#548)
This commit is contained in:
parent
ab1d652f17
commit
3842ec6bb0
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2020 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.matrix.android.api.extensions
|
||||
|
||||
fun CharSequence.ensurePrefix(prefix: CharSequence): CharSequence {
|
||||
return when {
|
||||
startsWith(prefix) -> this
|
||||
else -> "$prefix$this"
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ import android.util.Patterns
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.google.i18n.phonenumbers.NumberParseException
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil
|
||||
import im.vector.matrix.android.api.extensions.ensurePrefix
|
||||
|
||||
fun Boolean.toOnOff() = if (this) "ON" else "OFF"
|
||||
|
||||
@ -38,11 +39,10 @@ fun CharSequence.isEmail() = Patterns.EMAIL_ADDRESS.matcher(this).matches()
|
||||
|
||||
/**
|
||||
* Check if a CharSequence is a phone number
|
||||
* FIXME It does not work?
|
||||
*/
|
||||
fun CharSequence.isMsisdn(): Boolean {
|
||||
return try {
|
||||
PhoneNumberUtil.getInstance().parse(this, null)
|
||||
PhoneNumberUtil.getInstance().parse(ensurePrefix("+"), null)
|
||||
true
|
||||
} catch (e: NumberParseException) {
|
||||
false
|
||||
|
Loading…
Reference in New Issue
Block a user