Search code examples
javascriptasp.net-mvcasp.net-mvc-5

Advanced search with a single textbox


I am trying to perform a search using a single textbox for the search.

The idea is that the user can search the textbox either by Customer Name, Email, Phone Number, or Address.

I am analyzing the best possible way within my reach, i don't know if any of you have had the opportunity to work with something similar.

I do not know if using Regular Expressions I can identify the value entered by the user to know if I enter a phone number, address or email.

Thanks in advance, any example or contribution would be helpful.

This is my client class but my doubt is to identify the value of the text typed by the user.

public class Client
    {
        [Key]
        public int Id { get; set; }

        [StringLength(50)]
        public string FirstName { get; set; }

        [StringLength(50)]
        public string MidName { get; set; }

        [StringLength(50)]
        public string LastName { get; set; }

        [StringLength(50)]
        public string Email { get; set; }

        public virtual ICollection<Phone> Phones { get; set; }

        public virtual ICollection<Address> Address { get; set; }
    }

Thanks


Solution

  • Hello I solved using the example of @Tomato32

    • It's only text = Full name
    • Only numbers = Phone
    • Only numbers and Length of 5 = Zip code
    • Text + numbers = Address

    thanks