-
Notifications
You must be signed in to change notification settings - Fork 130
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 #13364 from woocommerce/issue/12439-validation-wit…
…h-type-delay Validation with delay
- Loading branch information
Showing
6 changed files
with
401 additions
and
17 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...in/com/woocommerce/android/ui/orders/wooshippinglabels/address/AddressValidationHelper.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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.woocommerce.android.ui.orders.wooshippinglabels.address | ||
|
||
import com.woocommerce.android.R | ||
import com.woocommerce.android.viewmodel.ResourceProvider | ||
import javax.inject.Inject | ||
|
||
class AddressValidationHelper @Inject constructor( | ||
private val resourceProvider: ResourceProvider | ||
) { | ||
fun validateAtLeastOneOf(vararg values: String): String? { | ||
return if (values.all { it.isEmpty() || it.isBlank() }) { | ||
resourceProvider.getString(R.string.woo_shipping_field_required_error) | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
fun validateFieldRequired(value: String): String? { | ||
return if (value.isEmpty() || value.isBlank()) { | ||
resourceProvider.getString(R.string.woo_shipping_field_required_error) | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
fun validateUSCustomsPhone(value: String): String? { | ||
return when { | ||
value.isEmpty() || value.isBlank() -> resourceProvider.getString(R.string.woo_shipping_field_required_error) | ||
value.replace(Regex("^1|[^\\d]"), "").length != US_PHONE_NUMBER_LENGTH -> { | ||
resourceProvider.getString(R.string.shipping_label_destination_address_phone_invalid) | ||
} | ||
|
||
else -> null | ||
} | ||
} | ||
|
||
fun validateCustomsPhone(value: String): String? { | ||
return when { | ||
value.isEmpty() || value.isBlank() -> resourceProvider.getString(R.string.woo_shipping_field_required_error) | ||
value.contains(Regex("\\d")).not() -> { | ||
resourceProvider.getString(R.string.shipping_label_destination_address_phone_invalid) | ||
} | ||
else -> null | ||
} | ||
} | ||
|
||
companion object { | ||
private const val US_PHONE_NUMBER_LENGTH = 10 | ||
} | ||
} |
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
Oops, something went wrong.