title: Xamarin Forms Password and Confirm Password Validation
body: <p>I have a <code>Xamarin Forms</code> application in which I have a registration form in which I need to validate Password and Confirm Password fields should be same.</p>
  
  <p>Is there any way to implement this using <code>Xamarin Behaviour</code>?</p>
  
  <p>I have already implemented <code>Xamarin Behaviour</code> for <code>Required Field</code> validation and <code>Email Regex</code> validation like this below-</p>
  
  <pre><code>public class RequiredValidatorBehavior : Behavior&lt;Entry&gt;
      {
          static readonly BindablePropertyKey IsValidPropertyKey = BindableProperty.CreateReadOnly("IsValid", typeof(bool), typeof(RequiredValidatorBehavior), false);
          static readonly BindableProperty IsValidProperty = IsValidPropertyKey.BindableProperty;
  
          public bool IsValid
          {
              get { return (bool)base.GetValue(IsValidProperty); }
              private set { base.SetValue(IsValidPropertyKey, value); }
          }
  
          protected override void OnAttachedTo(Entry bindable)
          {
              bindable.Unfocused += HandleFocusChanged;
              base.OnAttachedTo(bindable);
          }
          protected override void OnDetachingFrom(Entry bindable)
          {
              bindable.Unfocused -= HandleFocusChanged;
              base.OnDetachingFrom(bindable);
          }
          void HandleFocusChanged(object sender, FocusEventArgs e)
          {
              IsValid = !string.IsNullOrEmpty (((Entry)sender).Text);
          }
      }
  </code></pre>
  
  <p>Implementation of <code>Behaviour</code> in <code>XAML Content Page</code>-</p>
  
  <pre><code>&lt;Entry x:Name="password" Placeholder="New Password"&gt;
      &lt;Entry.Behaviors&gt;
          &lt;local:RequiredValidatorBehavior x:Name="passwordValidator"/&gt;   
      &lt;/Entry.Behaviors&gt;
  &lt;/Entry&gt;
  </code></pre>
  
  <p>The problem is - I am new in <code>Xamarin</code> development and have no idea how can I get the value of both <code>Password</code> and <code>Confirm Password</code> fields in <code>Behaviour</code> so that I can compare them. I do not wish to compare them on click of button when the form is submitted, fields should be compared while the user is typing in the fields. Any code, help or guidance is appreciable.</p>