0

I have an account form, created by Angular Form and connected to a Firebase real-time database. In Angular, I write the following code

accountsForm: FormGroup = new FormGroup({
    $key: new FormControl(null),
    accountNo: new FormControl('', [Validators.required, Validators.maxLength(6), Validators.minLength(6)]),  
});

The accountNo should be 'Required, 6 digits and Unique'. So In Angular, How can I do account No. unique?

Nicholas K
  • 15,148
  • 7
  • 31
  • 57
HTML Man
  • 937
  • 4
  • 16
  • 40
  • Are you going to pre-populate the account no or is the user going to enter it? – Nicholas K Mar 14 '20 at 11:36
  • the user is going to enter it – HTML Man Mar 14 '20 at 11:37
  • So you need to verify that the number entered by the user is not already present with the Firebase via an API. – Nicholas K Mar 14 '20 at 11:39
  • No API at all. I need to do that in client side, I don't know if Firebase can help. By the way I'm using '@angular/fire' library – HTML Man Mar 14 '20 at 11:43
  • Does Firebase give you an API that you can invoke to find out all the existing account numbers? Unless you verify it in Firebase there's no way you can find out whether the number exists or not. – Nicholas K Mar 14 '20 at 11:45
  • I don't know, I just connect myApp to firbase – HTML Man Mar 14 '20 at 11:46
  • You'll need to write it then OR find out if it provides some already existing API. – Nicholas K Mar 14 '20 at 11:47
  • To make something unique in Firebase Realtime Database, you'll want to use it as the keys for nodes in a certain location. So something like `/accounts/b=nr123`, `/accounts/nr234`, as that implicitly guarantees the account numbers are unique. See https://stackoverflow.com/a/25328654, https://stackoverflow.com/a/39151205, and more from this list https://www.google.com/search?q=site:stackoverflow.com+firebase+realtime+database+unique+value – Frank van Puffelen Mar 14 '20 at 15:08

0 Answers0