Skip to content

Commit

Permalink
[#28 feature] url validate 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahn-seokjoo committed Jun 27, 2024
1 parent e562142 commit 6f21bef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions domain/src/main/kotlin/clipboard/ClipboardUrlUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package clipboard

fun String.isValidUrl(): Boolean {
val urlPattern = "^https?://([a-zA-Z0-9.-]+)(:[0-9]{1,5})?(/.*)?$".toRegex()
return this.matches(urlPattern)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.text.AnnotatedString
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.LifecycleResumeEffect
import clipboard.isValidUrl
import com.mashup.dorabangs.core.designsystem.component.snackbar.DoraSnackBar
import com.mashup.dorabangs.core.designsystem.theme.DoraTypoTokens
import org.orbitmvi.orbit.compose.collectAsState
Expand All @@ -39,7 +40,7 @@ fun HomeRoute(
runCatching {
view.post {
copiedText = clipboardManager.getText()?.text.orEmpty()
shouldSnackBarShown = copiedText.isNotBlank()
shouldSnackBarShown = copiedText.isNotBlank() && copiedText.isValidUrl()
}
}
onPauseOrDispose {
Expand Down

0 comments on commit 6f21bef

Please sign in to comment.