0

I am asking users to enter path to controller files like

abc/cab
cde/ter/tyu

I am unable to validate it using

var regexString =/^([a-zA-Z\]+)*$/;

Can you please help me correct this. text like abc//text and abc/text/ and abc/text// and /abc/text also should return false. There should be no slash at beginning and ending also.

3 Answers 3

1

Try it like this:

var regexString = /^([a-z]+\/)*[a-z]+$/i;

Will work for:

abc/cab
abc/cab/bla

but won't for:

abc/cab/
/abc/cab
/abc/cab/
abc//sdgf
abc//sdgf/
/abc//sdgf
Sign up to request clarification or add additional context in comments.

Comments

1

This should work fine:

var regexString =/^[a-zA-Z]+(\/[a-zA-Z]+)*$/;

And will match

abc
abc/cab
cde/ter/ger

But not

/abc/sucks
abc//text
abc/text/
abc/text//

1 Comment

@ h2ooooooo - But its allowing text like abc//text and abc/text/ and abc/text// also. How do i prevent this
0

Here is a regular expression which is going to match a string with parameters you described:

/^([a-zA-Z]+\/[a-zA-Z]+)+$/

Here is an example:

var r = /^([a-zA-Z]+\/[a-zA-Z]+)+$/;
r.test('/ad/sd'); //false
r.test('as//sd'); //false
r.test('as/sd/'); //false
r.test('as/sd'); //true

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.