Browse Source

Input validation added on Login Screen..

Khubaib 1 year ago
parent
commit
804c014c67

+ 1 - 1
app/build.gradle.kts

@@ -74,7 +74,7 @@ dependencies {
     implementation("androidx.navigation:navigation-compose:2.7.7")
     implementation("androidx.compose.material:material-icons-extended:1.6.1")
     implementation("androidx.compose.ui:ui-text-google-fonts:1.6.1")
-    implementation("androidx.compose.foundation:foundation:1.4.0-alpha04")
+    implementation("androidx.compose.foundation:foundation:1.6.3")
 
     // Retrofit
     implementation("com.squareup.retrofit2:retrofit:2.9.0")

+ 140 - 39
app/src/main/java/com/vpn/fastestvpnservice/screens/LoginScreen.kt

@@ -4,6 +4,7 @@ package com.vpn.fastestvpnservice.screens
 import android.content.res.Configuration
 import android.gesture.Gesture
 import android.util.Log
+import android.widget.TextView
 import android.widget.Toast
 import androidx.activity.OnBackPressedCallback
 import androidx.compose.foundation.BorderStroke
@@ -35,11 +36,13 @@ import androidx.compose.foundation.text.KeyboardActionScope
 import androidx.compose.foundation.text.KeyboardActions
 import androidx.compose.foundation.text.KeyboardOptions
 import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.AddAlert
 import androidx.compose.material.icons.filled.Email
 import androidx.compose.material.icons.filled.Home
 import androidx.compose.material.icons.filled.Lock
 import androidx.compose.material.icons.filled.Visibility
 import androidx.compose.material.icons.filled.VisibilityOff
+import androidx.compose.material.icons.filled.Warning
 import androidx.compose.material.icons.outlined.Visibility
 import androidx.compose.material3.Button
 import androidx.compose.material3.ButtonColors
@@ -50,6 +53,9 @@ import androidx.compose.material3.ElevatedButton
 import androidx.compose.material3.Icon
 import androidx.compose.material3.IconButton
 import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.OutlinedTextField
+import androidx.compose.material3.Shapes
+import androidx.compose.material3.SnackbarDefaults
 import androidx.compose.material3.Text
 import androidx.compose.material3.TextField
 import androidx.compose.material3.TextFieldColors
@@ -102,6 +108,7 @@ import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.AddText
 import com.vpn.fastestvpnservice.sealedClass.Screen
 import com.vpn.fastestvpnservice.ui.theme.outfitFontFamily
 import com.vpn.fastestvpnservice.viewmodels.LoginViewModel
+import com.vpn.fastestvpnservice.views.CustomValidation
 import kotlinx.coroutines.delay
 import kotlin.coroutines.coroutineContext
 import kotlin.random.Random
@@ -119,6 +126,11 @@ fun Login(navHostController: NavHostController) {
     var textChanged by remember { mutableStateOf("") }
     var passwordChanged by remember { mutableStateOf("") }
     var passwordVisible by remember { mutableStateOf(false) }
+    var showErrorEmail by remember { mutableStateOf(false) }
+    var showErrorPass1 by remember { mutableStateOf(false) }
+    var showErrorPass2 by remember { mutableStateOf(false) }
+
+
 
     val context = LocalContext.current
     var basePreferenceHelper = BasePreferenceHelper(context)
@@ -167,7 +179,7 @@ fun Login(navHostController: NavHostController) {
             Spacer(modifier = Modifier.height(50.dp))
 
             TextMsg(
-                text = "Welcome Back!",
+                text = "Welcome Back! $showErrorPass2",
                 color = Color.White,
                 style = MaterialTheme.typography.displayLarge
             )
@@ -185,6 +197,7 @@ fun Login(navHostController: NavHostController) {
 
             Spacer(modifier = Modifier.height(20.dp))
 
+
             TextField(
                 value = textChanged,
                 onValueChange = {
@@ -206,7 +219,8 @@ fun Login(navHostController: NavHostController) {
                     .height(60.dp)
                     .border(
                         1.dp,
-                        color = colorResource(id = R.color.white),
+                        color = if (showErrorEmail) colorResource(id = R.color.red)
+                        else colorResource(id = R.color.white),
                         shape = RoundedCornerShape(16.dp)
                     )
                     .clickable() { },
@@ -256,8 +270,23 @@ fun Login(navHostController: NavHostController) {
 
             )
 
+            if (showErrorEmail) {
+                ShowErrorRow(errorText = "Email is Empty")
+
+            }
+
             Spacer(modifier = Modifier.height(20.dp))
 
+            val color = if (showErrorPass1) {
+                colorResource(id = R.color.red)
+            }
+            else if (showErrorPass2) {
+                colorResource(id = R.color.red)
+            }
+            else {
+                colorResource(id = R.color.grey_password_field)
+            }
+
             TextField(
                 value = passwordChanged,
                 onValueChange = {
@@ -281,11 +310,11 @@ fun Login(navHostController: NavHostController) {
                     .height(60.dp)
                     .border(
                         1.dp,
-                        color = colorResource(id = R.color.grey_password_field),
+                        color = color,
                         shape = RoundedCornerShape(16.dp)
                     )
                     .background(color = colorResource(id = R.color.transparent))
-                    .clickable() { },
+                    .clickable() {},
 
                 shape = RoundedCornerShape(15.dp),
 //                placeholder = {
@@ -368,6 +397,14 @@ fun Login(navHostController: NavHostController) {
                 }
                 )
 
+            if (showErrorPass1) {
+                ShowErrorRow(errorText = "Password is Empty")
+            }
+            else if (showErrorPass2) {
+                ShowErrorRow(errorText = "Should be 3 or more!")
+            }
+
+
             Spacer(modifier = Modifier.height(20.dp))
             ClickableText(
                 onClick = {
@@ -396,7 +433,19 @@ fun Login(navHostController: NavHostController) {
             textChanged,
             passwordChanged,
             loginViewModel = loginViewModel,
-            basePreferenceHelper
+            basePreferenceHelper,
+            showErrorEmail = {
+                showErrorEmail = it
+            },
+            showErrorEmail,
+            showErrorPass = {
+                showErrorPass1 = it
+            },
+            showErrorPass1,
+            showErrorPass2 = {
+                showErrorPass2 = it
+            },
+            showErrorPass2
             )
         Row (
             modifier = Modifier
@@ -404,31 +453,36 @@ fun Login(navHostController: NavHostController) {
                 .padding(57.dp),
         ){
             TextMsgSignUp(navHostController = navHostController, loginViewModel, readOnly!!)
-//            Text(
-//                modifier = Modifier
-//                    .padding(0.dp),
-//                fontSize = 14.sp,
-//                fontWeight = FontWeight.Normal,
-//                fontStyle = FontStyle.Normal,
-//                text = "Don't have an account? ",
-//                color = Color.White,
-//            )
-//            ClickableText(
-//                onClick = {
-//                    navHostController.navigate(Screen.SignUp.route)
-//                },
-//                modifier = Modifier
-//                    .padding(0.dp),
-//                style = TextStyle(
-//                    fontSize = 14.sp,
-//                    fontStyle = FontStyle.Normal,
-//                    color = colorResource(id = R.color.yellow_text),
-//                ),
-//                text = AnnotatedString(" Sign Up"),
-//            )
         }
     }
+}
+
 
+@Composable
+fun ColumnScope.ShowErrorRow(
+    errorText: String
+) {
+    Row(
+        verticalAlignment = Alignment.CenterVertically,
+        modifier = Modifier
+            .align(Alignment.Start)
+            .padding(start = 16.dp, top = 8.dp)
+    ) {
+        Icon(imageVector = Icons.Default.Warning,
+            contentDescription = "Error",
+            tint = colorResource(id = R.color.red),
+            modifier = Modifier.size(14.dp)
+        )
+        Text(text = errorText,
+            style = TextStyle(
+                fontFamily = outfitFontFamily,
+                fontWeight = FontWeight.Normal,
+                fontSize = 14.sp,
+                color = colorResource(id = R.color.red)
+            ),
+            modifier = Modifier.padding(start = 5.dp)
+        )
+    }
 }
 
 @Composable
@@ -477,10 +531,16 @@ fun BoxScope.SignInButton(
     email: String,
     password: String,
     loginViewModel: LoginViewModel,
-    prefHelper: BasePreferenceHelper
+    prefHelper: BasePreferenceHelper,
+    showErrorEmail: (Boolean) -> Unit,
+    isError: Boolean,
+    showErrorPass: (Boolean) -> Unit,
+    isErrorPass: Boolean,
+    showErrorPass2: (Boolean) -> Unit,
+    isErrorPass2: Boolean
 ) {
 //    var showLoader by remember { mutableStateOf(false) }
-
+//    Log.d("test_login_text", "$email $password")
     if (loginViewModel.liveDataLoginStatus.value == true) {
         var progress by remember { mutableFloatStateOf(0.1F) }
 
@@ -503,6 +563,28 @@ fun BoxScope.SignInButton(
             strokeWidth = 5.dp,
         )
     }
+    val customValidation = CustomValidation()
+
+    if (isError) {
+        if (email.isNotEmpty()) {
+            showErrorEmail(false)
+        }
+    }
+
+    if (isErrorPass) {
+        if (password.isNotEmpty()) {
+            showErrorPass(false)
+        }
+    }
+
+    if (isErrorPass2) {
+        if (password.isNotEmpty()) {
+            val isErrorPassSize = customValidation.isValidPassword(password)
+            if (isErrorPassSize) {
+                showErrorPass2(false)
+            }
+        }
+    }
 
     Button(
         modifier = Modifier
@@ -517,19 +599,37 @@ fun BoxScope.SignInButton(
             .clickable() { },
         onClick = {
             Log.d("test_api_response live", "Login Clicked:")
+
+            val isErrors = customValidation.isValidText(email, "Email")
+            showErrorEmail(!isErrors)
+
+            val isError1 = customValidation.isValidText(password, "Password")
+            showErrorPass(!isError1)
+
+            val isError2 = customValidation.isValidPassword(password)
+            if (password.isNotEmpty()) {
+                showErrorPass2(!isError2)
+            }
+
 //            showLoader = true
             if (loginViewModel.liveDataLoginStatus.value == false) {
                 Log.d("test_api_response live", "SignIn: $email $password")
 
-                if (email.isNotEmpty() && password.isNotEmpty()) {
-                    loginViewModel.setLoginStatus(true)
-                    loginViewModel.loginRequest(
-                        email,
-                        password,
-                        "android",
-                        "11",
-                        "3.2.4"
-                    )
+                if (customValidation.isValidText(email, "Email") &&
+                    customValidation.isValidText(password, "Password") &&
+                    customValidation.isValidPassword(password)) {
+                    Log.d("test_login_text", "true")
+
+                    if (email.isNotEmpty() && password.isNotEmpty()) {
+                        loginViewModel.setLoginStatus(true)
+                        loginViewModel.loginRequest(
+                            email,
+                            password,
+                            "android",
+                            "11",
+                            "3.2.4"
+                        )
+                    }
                 }
 
             }
@@ -543,7 +643,8 @@ fun BoxScope.SignInButton(
     )
     {
         Text(text = "Sign In",
-            style = MaterialTheme.typography.titleMedium
+            style = MaterialTheme.typography.titleMedium,
+            textAlign = TextAlign.Center
         )
 
         val loginData by loginViewModel.liveDataUserResponse.observeAsState()

+ 63 - 31
app/src/main/java/com/vpn/fastestvpnservice/screens/SignUpScreen.kt

@@ -39,6 +39,7 @@ import androidx.compose.material3.ButtonDefaults
 import androidx.compose.material3.CircularProgressIndicator
 import androidx.compose.material3.Icon
 import androidx.compose.material3.IconButton
+import androidx.compose.material3.MaterialTheme
 import androidx.compose.material3.Text
 import androidx.compose.material3.TextField
 import androidx.compose.material3.TextFieldDefaults
@@ -74,6 +75,7 @@ import androidx.compose.ui.text.input.KeyboardType
 import androidx.compose.ui.text.input.PasswordVisualTransformation
 import androidx.compose.ui.text.input.VisualTransformation
 import androidx.compose.ui.text.style.LineHeightStyle
+import androidx.compose.ui.text.style.TextAlign
 import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
@@ -83,8 +85,10 @@ import androidx.navigation.compose.rememberNavController
 import com.vpn.fastestvpnservice.R
 import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
 import com.vpn.fastestvpnservice.sealedClass.Screen
+import com.vpn.fastestvpnservice.ui.theme.outfitFontFamily
 import com.vpn.fastestvpnservice.viewmodels.LoginViewModel
 import com.vpn.fastestvpnservice.viewmodels.SignUpViewModel
+import com.vpn.fastestvpnservice.views.CustomValidation
 import kotlinx.coroutines.delay
 
 @OptIn(ExperimentalComposeUiApi::class)
@@ -171,8 +175,7 @@ fun SignUp(navHostController: NavHostController) {
                     .padding(start = 15.dp)
                     .align(Alignment.Start)
                 ,
-                fontSize = 28.sp,
-                fontWeight = FontWeight.Medium,
+                style = MaterialTheme.typography.displayLarge,
                 text = "Hello There!",
                 color = Color.White,
             )
@@ -180,9 +183,13 @@ fun SignUp(navHostController: NavHostController) {
                 modifier = Modifier
                     .padding(start = 15.dp)
                     .align(Alignment.Start),
-                fontSize = 14.sp,
-                fontWeight = FontWeight.Normal,
-                text = "Please login to your account.",
+                style = TextStyle(
+                    fontSize = 14.sp,
+                    fontFamily = outfitFontFamily,
+                    fontWeight = FontWeight.Normal,
+                    lineHeight = 30.sp
+                ),
+                text = "Please register your account.",
                 color = colorResource(id = R.color.light_grey),
             )
             Spacer(modifier = Modifier.height(20.dp))
@@ -193,12 +200,14 @@ fun SignUp(navHostController: NavHostController) {
                     textChanged = it
                 },
                 readOnly = isSignUpEnabled,
-
                 textStyle = TextStyle(
-                    fontSize = 20.sp,
                     color = colorResource(id = R.color.white),
-
-                    ),
+                    fontFamily = outfitFontFamily,
+                    fontWeight = FontWeight.Normal,
+                    fontSize = 14.sp,
+                    lineHeight = 22.sp,
+                    letterSpacing = 0.21.sp
+                ),
                 modifier = Modifier
                     .padding(start = 15.dp, end = 15.dp, top = 10.dp)
                     .align(Alignment.Start)
@@ -220,7 +229,9 @@ fun SignUp(navHostController: NavHostController) {
                     Text(text = "Email",
                         style = TextStyle(
                             colorResource(id = R.color.white),
-                            fontSize = 12.sp
+                            fontFamily = outfitFontFamily,
+                            fontWeight = FontWeight.Medium,
+                            fontSize = 12.sp,
                         )
                     )
                 },
@@ -265,12 +276,14 @@ fun SignUp(navHostController: NavHostController) {
                     passwordChanged = it
                 },
                 readOnly = isSignUpEnabled,
-
                 textStyle = TextStyle(
-                    fontSize = 20.sp,
                     color = colorResource(id = R.color.white),
-
-                    ),
+                    fontFamily = outfitFontFamily,
+                    fontWeight = FontWeight.Normal,
+                    fontSize = 14.sp,
+                    lineHeight = 22.sp,
+                    letterSpacing = 0.21.sp
+                ),
                 modifier = Modifier
                     .padding(start = 15.dp, end = 15.dp)
                     .align(Alignment.Start)
@@ -292,6 +305,8 @@ fun SignUp(navHostController: NavHostController) {
                     Text(text = "Password",
                         style = TextStyle(
                             colorResource(id = R.color.white),
+                            fontFamily = outfitFontFamily,
+                            fontWeight = FontWeight.Normal,
                             fontSize = 16.sp
                         )
                     )
@@ -383,8 +398,11 @@ fun SignUp(navHostController: NavHostController) {
                 Text(
                     modifier = Modifier
                         .padding(start = 15.dp),
-                    fontSize = 15.sp,
-                    fontStyle = FontStyle.Normal,
+                    style = TextStyle(
+                        fontFamily = outfitFontFamily,
+                        fontWeight = FontWeight.Normal,
+                        fontSize = 16.sp,
+                    ),
                     text = "By creating your account, you agree to",
                     color = colorResource(id = R.color.white),
                 )
@@ -416,8 +434,9 @@ fun SignUp(navHostController: NavHostController) {
                         .padding(start = 15.dp),
                     text = AnnotatedString("Terms & Conditions"),
                     style = TextStyle(
-                        fontSize = 15.sp,
-                        fontStyle = FontStyle.Normal,
+                        fontFamily = outfitFontFamily,
+                        fontWeight = FontWeight.Normal,
+                        fontSize = 16.sp,
                         color = colorResource(id = R.color.yellow_text)
                     )
                 )
@@ -435,9 +454,13 @@ fun SignUp(navHostController: NavHostController) {
             Text(
                 modifier = Modifier
                     .padding(0.dp),
-                fontSize = 15.sp,
-                fontWeight = FontWeight.Normal,
-                fontStyle = FontStyle.Normal,
+                style = TextStyle(
+                    fontFamily = outfitFontFamily,
+                    fontWeight = FontWeight.Normal,
+                    fontSize = 14.sp,
+                    textAlign = TextAlign.Right,
+                    lineHeight = 30.sp
+                ),
                 text = "Already have an account? ",
                 color = Color.White,
             )
@@ -464,10 +487,13 @@ fun SignUp(navHostController: NavHostController) {
                 modifier = Modifier
                     .padding(0.dp),
                 style = TextStyle(
-                    fontSize = 15.sp,
-                    fontStyle = FontStyle.Normal,
+                    fontFamily = outfitFontFamily,
+                    fontWeight = FontWeight.Normal,
+                    fontSize = 14.sp,
+                    textAlign = TextAlign.Right,
+                    lineHeight = 30.sp,
                     color = colorResource(id = R.color.yellow),
-                ),
+                    ),
                 text = AnnotatedString(" Sign In"),
             )
         }
@@ -484,6 +510,7 @@ fun BoxScope.SignUpButton(
     val loginViewModel: LoginViewModel = viewModel()
     val context = LocalContext.current
     val prefHelper = BasePreferenceHelper(context)
+    val customValidation = CustomValidation()
 
     if (signUpViewModel.liveDataSignUpStatus.value == true) {
         var progress by remember { mutableFloatStateOf(0.1F) }
@@ -515,8 +542,16 @@ fun BoxScope.SignUpButton(
 
             if (signUpViewModel.liveDataSignUpStatus.value == false) {
                 Log.d("test_button", "onClick")
-                signUpViewModel.setSignUpStatus(true)
-                signUpViewModel.signUp(email, password)
+
+                if (customValidation.isValidText(email, "Email") &&
+                    customValidation.isValidText(password, "Password") &&
+                    customValidation.isValidPassword(password)) {
+                    if (customValidation.isValidEmail(email)) {
+                        signUpViewModel.setSignUpStatus(true)
+                        signUpViewModel.signUp(email, password)
+                    }
+                }
+
             }
         },
         modifier = Modifier
@@ -537,11 +572,8 @@ fun BoxScope.SignUpButton(
     )
     {
         Text(text = "Sign Up",
-            style = TextStyle(
-                fontSize = 18.sp,
-                color = colorResource(id = R.color.blue_text),
-                fontWeight = FontWeight.Medium
-            ),
+            style = MaterialTheme.typography.titleMedium,
+            textAlign = TextAlign.Center
         )
 
         val signUpData = signUpViewModel.liveDataSignUp.observeAsState().value

+ 76 - 0
app/src/main/java/com/vpn/fastestvpnservice/views/CustomTextInputLayout.java

@@ -0,0 +1,76 @@
+package com.vpn.fastestvpnservice.views;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.Nullable;
+import androidx.core.content.ContextCompat;
+
+import com.vpn.fastestvpnservice.R;
+
+
+/**
+ * Created by developer007.ingic on 12/22/2017.
+ */
+
+public class CustomTextInputLayout extends LinearLayout {
+    TextView tvError;
+    Context ctx;
+
+    public CustomTextInputLayout(Context context) {
+        this(context, (AttributeSet) null);
+    }
+
+    public CustomTextInputLayout(Context context, AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
+
+    public CustomTextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs);
+        this.setOrientation(VERTICAL);
+        ctx = context;
+    }
+
+    public void setErrorEnabled() {
+        if(this.tvError==null) {
+//            this.tvError = new AppCompatTextView(ctx);
+            this.removeView(this.tvError);
+            this.tvError.setTextColor(ContextCompat.getColor(ctx, R.color.colorPrimary));
+            this.tvError.setTextSize(10.0f);
+            this.tvError.setVisibility(INVISIBLE);
+            this.tvError.setPadding(14, -1, 0, 0);
+            this.addView(this.tvError);
+        }
+    }
+
+    public void setError(@Nullable final CharSequence error) {
+        this.tvError.setText(error);
+        errorEnable(true);
+    }
+
+    public void setErrorMessage(@Nullable final CharSequence error) {
+        this.tvError.setText(error);
+    }
+
+    public void errorEnable(boolean isErrorShow) {
+        if (isErrorShow) {
+            tvError.setVisibility(VISIBLE);
+        } else {
+            if (tvError != null) {
+                tvError.setVisibility(INVISIBLE);
+                tvError.setText("");
+            }
+        }
+    }
+
+    public boolean isErrorEnable() {
+        if (tvError.getVisibility() == VISIBLE) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+}

+ 411 - 0
app/src/main/java/com/vpn/fastestvpnservice/views/CustomValidation.java

@@ -0,0 +1,411 @@
+package com.vpn.fastestvpnservice.views;
+
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.widget.AutoCompleteTextView;
+import android.widget.EditText;
+import android.widget.TextView;
+
+import androidx.compose.runtime.Composable;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+
+/**
+ * Created by adnanahmed on 1/11/2018.
+ */
+
+public class CustomValidation {
+
+    public boolean isValidText(String edittext, String fName) {
+        String validate = edittext;
+        validate = validate.replaceAll("\\s+", " ").trim();
+        //            edittext.setError(fName + " is Empty");
+        return !validate.isEmpty();
+    }
+    public boolean isValidPassword(String editText) {
+        String pass = editText.trim();
+        if (pass != null && pass.length() >= 3) {
+            return true;
+        }
+//        editText.setError("Should be greater than 3!");
+        return false;
+
+    }
+
+
+    public static boolean validateEmail(EditText editText, CustomTextInputLayout textInputLayout, String error) {
+        String email = editText.getText().toString().trim();
+        textInputLayout.errorEnable(false);
+
+//        if (email.isEmpty() || !isValidEmail(email)) {
+//            textInputLayout.setError(error);
+//            textInputLayout.requestFocus();
+////            btnLogin.setAlpha(0.5f);
+//            editText.requestFocus();
+//            return false;
+//        } else {
+//
+//            textInputLayout.setError("");
+//
+//        }
+
+        return true;
+    }
+
+
+
+    public static boolean validateName(EditText editText, CustomTextInputLayout textInputLayout, String error) {
+        String name = editText.getText().toString().trim();
+        textInputLayout.errorEnable(false);
+
+        if (name.isEmpty() || !isValidName(name) || name.length() <= 2) {
+            textInputLayout.setError(error);
+            textInputLayout.requestFocus();
+//            btnLogin.setAlpha(0.5f);
+            editText.requestFocus();
+            return false;
+        } else {
+
+            textInputLayout.setError("");
+
+        }
+
+        return true;
+    }
+
+
+    public static boolean validateTextView(TextView editText, CustomTextInputLayout textInputLayout, String error) {
+        String phone = editText.getText().toString().trim();
+        textInputLayout.errorEnable(false);
+
+        if (phone.isEmpty()) {
+            textInputLayout.setError(error);
+            textInputLayout.requestFocus();
+//            btnLogin.setAlpha(0.5f);
+            editText.requestFocus();
+            return false;
+        } else {
+
+            textInputLayout.setError("");
+
+        }
+
+        return true;
+    }
+
+    public static boolean validateLocation(AutoCompleteTextView editText, CustomTextInputLayout textInputLayout, String error) {
+        String name = editText.getText().toString().trim();
+        textInputLayout.errorEnable(false);
+
+        if (name.isEmpty() || name.length() <= 2) {
+            textInputLayout.setError(error);
+            textInputLayout.requestFocus();
+//            btnLogin.setAlpha(0.5f);
+            editText.requestFocus();
+            return false;
+        } else {
+
+            textInputLayout.setError("");
+
+        }
+
+        return true;
+    }
+
+    public static boolean validateSpecialization(AutoCompleteTextView editText, CustomTextInputLayout textInputLayout, String error) {
+        String name = editText.getText().toString().trim();
+        textInputLayout.errorEnable(false);
+
+        if (name.isEmpty() || name.length() <= 2) {
+            textInputLayout.setError(error);
+            textInputLayout.requestFocus();
+//            btnLogin.setAlpha(0.5f);
+            editText.requestFocus();
+            return false;
+        } else {
+
+            textInputLayout.setError("");
+
+        }
+
+        return true;
+    }
+
+    public static boolean validatePhone(EditText editText, CustomTextInputLayout textInputLayout, String error) {
+        String phone = editText.getText().toString().trim();
+        textInputLayout.errorEnable(false);
+
+        if (phone.isEmpty() || phone.length() <= 10) {
+            textInputLayout.setError(error);
+            textInputLayout.requestFocus();
+//            btnLogin.setAlpha(0.5f);
+            editText.requestFocus();
+            return false;
+        } else {
+
+            textInputLayout.setError("");
+
+        }
+
+        return true;
+    }
+
+    public static boolean validateWeightHeight(EditText editText, CustomTextInputLayout textInputLayout, String error) {
+        String weightHeight = editText.getText().toString().trim();
+        textInputLayout.errorEnable(false);
+
+        if (weightHeight.isEmpty() || weightHeight.length() <= 2) {
+            textInputLayout.setError(error);
+            textInputLayout.requestFocus();
+//            btnLogin.setAlpha(0.5f);
+            editText.requestFocus();
+            return false;
+        } else {
+
+            textInputLayout.setError("");
+
+        }
+
+        return true;
+    }
+
+    public static boolean validateNumber(EditText editText, CustomTextInputLayout textInputLayout, String error) {
+        String phone = editText.getText().toString().trim();
+        textInputLayout.errorEnable(false);
+
+        if (phone.isEmpty()) {
+            textInputLayout.setError(error);
+            textInputLayout.requestFocus();
+//            btnLogin.setAlpha(0.5f);
+            editText.requestFocus();
+            return false;
+        } else {
+
+            textInputLayout.setError("");
+
+        }
+
+        return true;
+    }
+
+    public static boolean validatePassword(EditText txtPassword, final CustomTextInputLayout textInputLayout, String error) {
+        if (txtPassword.getText().toString().isEmpty() || txtPassword.getText().toString().length() < 6) {
+            textInputLayout.setError(error);
+            textInputLayout.requestFocus();
+//            btnLogin.setAlpha(0.5f);
+            txtPassword.requestFocus();
+            return false;
+        } else {
+            textInputLayout.setError("");
+        }
+
+        txtPassword.addTextChangedListener(new TextWatcher() {
+            @Override
+            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+
+            }
+
+            @Override
+            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+                textInputLayout.setError("");
+            }
+
+            @Override
+            public void afterTextChanged(Editable editable) {
+
+            }
+        });
+
+        return true;
+    }
+
+    public static boolean validateConfirmPassword(EditText txtPassword, EditText txtConfirmPassword, final CustomTextInputLayout textInputLayout, String error) {
+        if (txtPassword.getText().toString().isEmpty() || txtPassword.getText().toString().length() < 6 || !(txtPassword.getText().toString().equals(txtConfirmPassword.getText().toString()))) {
+            textInputLayout.setError(error);
+            textInputLayout.requestFocus();
+//            btnLogin.setAlpha(0.5f);
+            txtPassword.requestFocus();
+            return false;
+        } else {
+            textInputLayout.setError("");
+        }
+
+        txtPassword.addTextChangedListener(new TextWatcher() {
+            @Override
+            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+
+            }
+
+            @Override
+            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+                textInputLayout.setError("");
+            }
+
+            @Override
+            public void afterTextChanged(Editable editable) {
+
+            }
+        });
+
+        return true;
+    }
+
+
+    public static boolean isValidWebsite(EditText text, final CustomTextInputLayout textInputLayout, String error) {
+        String emailPattern = "^(http:\\/\\/|https:\\/\\/)?(www.)?([a-zA-Z0-9]+).[a-zA-Z0-9]*.[\u200C\u200Ba-z]{2}\\.([a-z]+)?$";
+        text.requestFocus();
+        CharSequence inputStr = text.getText().toString();
+        Pattern pattern = Pattern.compile(emailPattern, Pattern.CASE_INSENSITIVE);
+        Matcher matcher = pattern.matcher(inputStr.toString().trim());
+        if (matcher.matches()) {
+            textInputLayout.setError("");
+            return true;
+        }
+        //  textInputLayout.requestFocus();
+        textInputLayout.setError(error);
+        text.addTextChangedListener(new TextWatcher() {
+            @Override
+            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+
+            }
+
+            @Override
+            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+                textInputLayout.setError("");
+            }
+
+            @Override
+            public void afterTextChanged(Editable editable) {
+
+            }
+        });
+        return false;
+    }
+
+    public static boolean isValidEditText(EditText text, final CustomTextInputLayout textInputLayout, String error) {
+        String emailPattern = "^(?=\\s*\\S).*$";
+        text.requestFocus();
+        CharSequence inputStr = text.getText().toString();
+        Pattern pattern = Pattern.compile(emailPattern, Pattern.CASE_INSENSITIVE);
+        Matcher matcher = pattern.matcher(inputStr.toString().trim());
+        if (matcher.matches()) {
+            textInputLayout.setError("");
+            return true;
+        }
+        textInputLayout.requestFocus();
+        textInputLayout.setError(error);
+        text.addTextChangedListener(new TextWatcher() {
+            @Override
+            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+
+            }
+
+            @Override
+            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+                textInputLayout.setError("");
+            }
+
+            @Override
+            public void afterTextChanged(Editable editable) {
+
+            }
+        });
+        return false;
+    }
+
+    public static boolean isValidNumericField(EditText text, CustomTextInputLayout textInputLayout, String error) {
+        String emailPattern = "[0-9]{0,100}$";
+        CharSequence inputStr = text.getText().toString();
+        Pattern pattern = Pattern.compile(emailPattern, Pattern.CASE_INSENSITIVE);
+        Matcher matcher = pattern.matcher(inputStr);
+        if (matcher.matches() && text.getText().toString().length() > 0) {
+            textInputLayout.errorEnable(false);
+            return true;
+        }
+        textInputLayout.requestFocus();
+        textInputLayout.setErrorEnabled();
+        textInputLayout.setError(error);
+        text.requestFocus();
+        return false;
+    }
+
+    public static boolean isValidPassword(String text, String conformpass, CustomTextInputLayout textInputLayout, String error) {
+        if (text.equals(conformpass)) {
+            textInputLayout.setError("");
+            return true;
+        }
+        textInputLayout.setError(error);
+        return false;
+    }
+
+    public static boolean validateLength(EditText editText, final CustomTextInputLayout textInputLayout, String error, String min, String max) {
+        String emailPattern = "^.{" + min + "," + max + "}$";
+        CharSequence inputStr = editText.getText().toString();
+        Pattern pattern = Pattern.compile(emailPattern, Pattern.CASE_INSENSITIVE);
+        Matcher matcher = pattern.matcher(inputStr);
+        if (matcher.matches()) {
+            textInputLayout.setError("");
+            return true;
+        }
+        textInputLayout.requestFocus();
+        textInputLayout.setError(error);
+        editText.requestFocus();
+        editText.addTextChangedListener(new TextWatcher() {
+            @Override
+            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+
+            }
+
+            @Override
+            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+                textInputLayout.setError("");
+            }
+
+            @Override
+            public void afterTextChanged(Editable editable) {
+
+            }
+        });
+        return false;
+    }
+
+    public boolean isValidEmail(String email) {
+        String emailPattern = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+                + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
+
+
+        CharSequence inputStr = email;
+
+        Pattern pattern = Pattern.compile(emailPattern, Pattern.CASE_INSENSITIVE);
+        Matcher matcher = pattern.matcher(inputStr);
+
+        if (matcher.matches())
+            return true;
+//        else
+//            Utils.showSnackBar(ctx,view,"Email Not Valid",ctx.getResources().getColor(R.color.grayColor));
+
+          /*  editText.setError("Email Not Valid");
+        editText.requestFocus();
+*/
+        return false;
+    }
+
+    private static boolean isValidName(String email) {
+        String namePattern = "^[\\p{L} .'-]+$";
+
+
+        CharSequence inputStr = email;
+
+        Pattern pattern = Pattern.compile(namePattern, Pattern.CASE_INSENSITIVE);
+        Matcher matcher = pattern.matcher(inputStr);
+
+        if (matcher.matches())
+            return true;
+
+        return false;
+    }
+
+
+}