You only anchored the end of the pattern.
All this tests is that there is at least 1 alpha-numeric at the end of the test-string.
You probably wanted:
Regex str = new Regex(@"^[a-zA-Z0-9]+$");
to pattern match the whole string.
I'm unclear about what you mean by:
I want to insert value like
string1.string2
string1_string2
string1 string2
What does that have to do with the pattern?
[Edit: following comment below]
How about:
Regex str = new Regex(@"^[a-zA-Z0-9]+[ \._][a-zA-Z0-9]+$");
Will take two alphanumeric sequences separated by space, dot or underscore.
[Edit #2]
If you want to also match just a single alphanumeric sequence as well as two separated sequences, make the separator and second sequence optional:
Regex str = new Regex(@"^[a-zA-Z0-9]+(?:[ \._][a-zA-Z0-9]+)?$");