javascript - How to check first 5 chars & last 5 chars of a string? -
I am trying to validate a string only if its first letter is 5 characters and the last 5 letter characters :
What I have tried:
var userId = "12345abcde"; // Get the first and the second five characters first = five = userId.substring (0, 5); Var secondFive = userId.substring (5, 10); // Mill Global Letter And Encumbers Of AST = / [a-z, A-Z] / g; Var aNum = / [0- 9] / g; Var c = userId.match (aNum); // First try first first ... if (firstFive === C) {warning ('yes'); } And {warnings ('Nop'); } this alert nop .
That's because firstFive is the string and c object? Where's the error in my thinking?
Live example:
Any tips? thank you in advanced!
Try
/ ^ [0-9] {5 }. * [Az] {5} $ / i.test ("12345abcde")
Comments
Post a Comment