regex in client script

Prem13
Tera Contributor

i tried with the below regex

var regexp = /\d{6}@\d{5}/;
var idi = id.match(regexp);

in this before "@" i should be able to enter 6 characters and after "@" it should contain alpha numeric characters  which should be 5 characters in length

1 ACCEPTED SOLUTION

Hi,

I'm not sure what you mean by "where I can enter more than 6 characters before '@' and 5 characters after '@'".

So, yes, you can, but your validation in your client script would then check that against the pattern you've defined and if it doesn't match/work with it...you would clear the field and maybe give an alert to say "please enter in 'x' format".

The regex doesn't literally block someone from entering in a bunch of characters...it's the validation in the client script that would check it.

For example, go to: https://regex101.com/

And in the regular expression field at the top of the website, put: \d{6}@[a-zA-Z0-9]{5}

Then do some test strings for yourself. You'll see on the right, in the Match Information section...they aren't matches UNTIL you do 6 numbers, then a '@' and then 5 characters of letters or numbers.

So for this to then work in SN, you have to add / to front and / to back of the pattern. So it now becomes: 

/\d{6}@[a-zA-Z0-9]{5}/

And then that should work.

But again, users can enter in all sorts of stuff in that field...it's the onChange client script that would check what they enter, against a pattern, and if it doesn't match....you'd clear the value and alert them to the pattern you're expecting.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

9 REPLIES 9

Prem,

Please be specific. This is what you have in your post:

in this before "@" i should be able to enter 6 characters and after "@" it should contain alpha numeric characters  which should be 5 characters in length

Which you then replied to someone else and said:

before "@" i should be able to enter 6 characters (numbers) and after "@" it should contain alpha numeric characters  which should be 5 characters in length

Now you're saying:

I need to type only 6 characters  before @ and 5 characters after @ 

is it possible to restrict character limit

Before "@" 6   

After "@" 5 

Since in both before and after i can enter n number of numbers

---

Please clarify what you want as this has now changed from what you've said twice earlier. What I posted above...allows for 6 numbers only, then a @, then 5 alphanumeric characters after (meaning could be numbers or letters). Have you tried to use what I posted?

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi allen,

Sorry for the trouble 

below is the actual one.

eg:-123123@12a12b

eg:-12342@17aas1

i tried with the regex which you provided where i can enter more than 6 characters before @ and 5 character after @  

 

Hi,

I'm not sure what you mean by "where I can enter more than 6 characters before '@' and 5 characters after '@'".

So, yes, you can, but your validation in your client script would then check that against the pattern you've defined and if it doesn't match/work with it...you would clear the field and maybe give an alert to say "please enter in 'x' format".

The regex doesn't literally block someone from entering in a bunch of characters...it's the validation in the client script that would check it.

For example, go to: https://regex101.com/

And in the regular expression field at the top of the website, put: \d{6}@[a-zA-Z0-9]{5}

Then do some test strings for yourself. You'll see on the right, in the Match Information section...they aren't matches UNTIL you do 6 numbers, then a '@' and then 5 characters of letters or numbers.

So for this to then work in SN, you have to add / to front and / to back of the pattern. So it now becomes: 

/\d{6}@[a-zA-Z0-9]{5}/

And then that should work.

But again, users can enter in all sorts of stuff in that field...it's the onChange client script that would check what they enter, against a pattern, and if it doesn't match....you'd clear the value and alert them to the pattern you're expecting.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Niamul Arifin
Tera Expert

I have a similar requirement that I am working on. 

My question is if I want to capture 5 characters, 6 characters, and characters after the '@' symbol, what should be the regex expression?

Currently, i am doing something like \d{6}@([a-zA-Z0-9]{5}) | ([a-zA-Z0-9]{6}) | ([a-zA-Z0-9]{7}) /

Actually nevermind, found the solution to this problem. the regex exp is 

\d{6}@[a-zA-Z0-9]{5,7}