-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1729 from OneSignal/user-model/email-sms-validation
[User Model] Add validation logic to add/remove email & sms subscriptions
- Loading branch information
Showing
5 changed files
with
111 additions
and
21 deletions.
There are no files selected for viewing
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
23 changes: 23 additions & 0 deletions
23
OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common/OneSignalUtils.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,29 @@ | ||
package com.onesignal.common | ||
|
||
import java.util.regex.Pattern | ||
|
||
object OneSignalUtils { | ||
@JvmStatic | ||
var sdkType = "native" | ||
|
||
@JvmStatic | ||
val sdkVersion: String = "050000" | ||
|
||
fun isValidEmail(email: String): Boolean { | ||
if (email.isEmpty()) | ||
return false | ||
|
||
val emRegex = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$" | ||
val pattern: Pattern = Pattern.compile(emRegex) | ||
return pattern.matcher(email).matches() | ||
} | ||
|
||
fun isValidPhoneNumber(number: String): Boolean { | ||
if (number.isEmpty()) | ||
return false | ||
|
||
val emRegex = "^\\+?[1-9]\\d{1,14}\$" | ||
val pattern: Pattern = Pattern.compile(emRegex) | ||
return pattern.matcher(number).matches() | ||
} | ||
} |
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
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
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