0

I am using the following regex.

/^(([0-9._]?)*([a-zA-Z._]|[a-zA-Z._][a-zA-Z0-9\-._]*[a-zA-Z0-9])\._)*([A-Za-z._]|[A-Za-z._][A-Za-z0-9\-._]*[A-Za-z0-9_])$/;

It fails for 1dsd.343.23fdf

but passes d1sd.343.23fdf

what is to be modified on the regex to allow first letter as a number.

anubhava
  • 761,203
  • 64
  • 569
  • 643
Rohit Kumar
  • 1,777
  • 2
  • 13
  • 26
  • 2
    It seems you can just add matching a digit in a character class in the second part. https://regex101.com/r/rgOJL9/1 But what do you want to match with this pattern? I see there are also underscores, so for the current data there will be not match in the first part. – The fourth bird Aug 22 '22 at 16:45
  • 2
    What are rules for your regex? – anubhava Aug 22 '22 at 16:46
  • i am not an expert on regex...... Its just that the above regex get's the job done... all i want it to allow first character as number....it fails on 1dsd.343.23fdf – Rohit Kumar Aug 22 '22 at 16:52
  • 2
    @RohitKumar You are welcome. Perhaps if you can list some other formats that should be allowed/rejected, maybe we can provide you with shorter pattern that would be a better fit. – The fourth bird Aug 22 '22 at 16:55

0 Answers0