-1

1.I need to allow maximum of 5 emails in email field on edit as part of UI validation.

2.It should take all emails separated by ;

3.All emails should be under specific domain.

4.Looking in JavaScript or in ReactJS.

Phani
  • 15
  • 4
  • Have you tried anything ? Please show what you've attempted so far. – JeanRemyDuboc Apr 26 '22 at 18:31
  • You need String.split(), String.trim(), regular expressions, etc. Given these parameters it's actually not too hard. Edit your question with code showing what you've tried, preferably as [mre]. –  Apr 26 '22 at 18:34
  • I'm able to restrict the user with specific domain. I'm not able to think of logic how to limit with maximum of 5 emails on edit. Due to security concern, my org has blocked stack overflow and hence I'm unable to keep the code snippet. Could you please help me with the simple code snippet ? Thanks in anticipation – Phani Apr 26 '22 at 18:35
  • I would use the string methods in javascript https://www.w3schools.com/js/js_string_methods.asp. To get your desired result you want to count how many ";" are in the text, then check it is not more than 5. You could store each email in an array, splitting the string where ";" is, then checking that everything after the "@" is the same in each email. – Callum S Apr 26 '22 at 18:37
  • You may not need JS for this task, use `pattern` attribute with some clever regex. Something like `(.+@example\.com(;|$)){1,5}` – Walk Apr 26 '22 at 18:51
  • May I request you to please write the sample snippet ? The above regex is not working. – Phani Apr 26 '22 at 19:18

1 Answers1

0

You can try something like this...

function checkValid(inputText) {

  if (
    inputText.split(";").length > 5 ||
    inputText.split(";").length !== inputText.split("@specific.domain").length - 1
  ) {
    // Show error
  } else {
    // Process emails
  }
  
}