Search code examples
javascriptemailcase-insensitive

How to remove case sensitivity from email in js


I want to remove the case sensitivity from emails when searching emails. For further explanation, If I search an email([email protected]) in a different ways like this '[email protected]' or '[email protected]' or '[email protected]'. I want to retrieve the email. If anyone can help, really appreciated.

Thank you


Solution

  • As pointed out in the comments, this email lookup operation is actually done by querying an Oracle database.

    In this case I would suggest to investigate whether it is possible to execute a query containing a case insensitive WHERE clause to filter on the Email column. I'm not an oracle db expert, but usually database systems allow to perform case insensitive queries, by using the proper collation. At least checkig if this is actually allowed is worth the effort.

    By doing so you will get the following advantages:

    • the actual computation is done on the database, so you are basically avoiding computation at the application level. Databases are highly optimazed for this kind of work and can leverage indexes to speed up the filtering
    • you will move less data on the network, because only the records which actually match your filter criteria will be transferred over the network to the machine running your application

    Another option you can consider, if running a case insensitive query is not supported by your database, is storing the email in a normalized form. You can save both the actual email value (with the original casing) and a normalized version of the email (for instance you can use the email value transformed in uppercase). Then, to perform case insensitive search, you can use the column containing the normalized email value in your WHERE clause. I would suggest to use this approach as a last resort, because you will increase the amount of data stored and you will make your queries less obvious: this is just a workaround to apply when case insensitive queries are not possible.